简体   繁体   中英

Is it possible to retrieve database records inside a Blade View (Laravel)?

I know database work shouldn't be done inside the view, but unless there's another way, I think I need to do it.

In my web application, I use the same sidebar for every web page and I want to display records from a table in the sidebar. I don't want to have to retrieve those records in EVERY controller method in my application (as there is a lot).

Is it possible to do this inside a blade view? Or is there another way I should do it?

You can attach controllers to views! This means anytime the view is called, the underlying controller is also called. This is called a View Composer

使用时应考虑视图作曲家https://laravel.com/docs/5.4/views#view-composers

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM