I was triing to list posts on other pages and I see that I need a view composer.
In the AppServiceProvider
public function boot(): void
{
View::composer('layouts.master', function ($view) {
$view->with('posts', Posts::get());
});
}
In my postcontroller
public function show() {
$posts = Post::get();
return view('posts.show', ['posts' => $posts]);
}
I get “Undefined type “AppModelsposts” in VS Code. I am able to display posts on a page. But I can’t create a view composer.
Code for view composer
View::composer('layouts.master', function ($view) {
$view->with('posts', Posts::get());
});