问题描述
我之前创建了3个作曲家视图,它们都可以正常工作,但是后来我又创建了一个似乎不起作用的视图.我一直在尝试使其工作,这似乎与我的代码无关.我会在这里放一部分,但我仍然不认为这是代码.
I created 3 composer views previously and they all work properly, but then I created another one, which doesn't seem to work. I've been trying to get it to work, it doesn't seem to be something related to my code. I will drop a piece of it here, but I still don't think it's the code.
提供者EvenComposerProvider:
Provider EvenComposerProvider:
public function register(){
$this->composeEven();
}
public function composeEven(){
view()->composer('includes.aklinkosesi', 'App\Http\Composers\EvenComposer');
}
Composer EvenComposer:
Composer EvenComposer:
class EvenComposer{
public function compose(View $view){
$view->with('evens', Even::orderBy('id','desc')->paginate(10));
}
}
然后我将提供程序包含在app.php
And than I included the provider inside app.php
App\Providers\EvenComposerProvider::class
当我尝试通过foreach
遍历$evens
时,会引发错误:
When I try to loop through $evens
with the foreach
, it throws the error:
我的粗略猜测是,Laravel无法编译app.php
My rough guess will be that, Laravel does not compile app.php
推荐答案
因此,以下是可能适用于同一人群的解决方案.首先尝试以下命令:
So here is the solutions which might work for people in same sitatuin.First try these commands:
composer update
php artisan config:clear
php artisan cache:clear
composer dumpautoload
php artisan cache:clear
我尝试了一些操作,而不是删除了bootstrap/cache/config
文件,并且该方法有效.
I tried a few of them than deleted bootstrap/cache/config
file and it worked.
这篇关于Composer View未将变量加载到视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!