I need to share a collection in all of my views. This collection contain the website news:
$news=NewsStory::orderBy('created_at', 'desc')->paginate(5);
How can I do this?
You can share View Data between all views. Just add this one line to the boot()
method in App\\Providers\\AppServiceProvider
:
view()->share('news', NewsStory::orderBy('created_at', 'desc')->paginate(5));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.