我正在尝试在我的页面中包含文件,其路径存储在我的数据库中。我试过了: -
@foreach($data as $articles)
@include( $articles->path )
<br />
@endforeach
这不起作用。我做错了什么。
我的文件位于视图中名为pages的文件夹中,我也添加了.blade.php扩展名。
答案 0 :(得分:2)
您需要确保您引用的路径实际上是作为视图文件夹中的文件存在,即
application/views/pages/articles/first-post.blade.php
我见过很多人做的一件事是将视图添加到主文件夹,但没有将其添加到包含路径,例如。
application/views/home/pages/articles/first-post.blade.php
此外,您似乎没有在@include中正确调用路径。应该使用点符号
@include('pages.articles.first-post);
您还需要确保不要尝试从捆绑包中获取视图。如果你是的话,你需要附加包名称。
@include('bundle_name::pages.articles.first-post');