[英]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. 在我的Web应用程序中,我对每个网页使用相同的侧边栏,我想显示侧边栏中表格的记录。 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 这称为View Composer
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.