我正在学习laravel并且出错了。你有什么建议吗? 我试过“composer dump-autoload”,但它没有解决这个问题。
Container.php第738行中的ErrorException:Class App \ Http \ Views \ Composers \ CatFormComposer不存在(查看: /Applications/MAMP/htdocs/lar/furbook.com/resources/views/cats/create.blade.php)
Container.php第738行中的ReflectionException:Class App \ Http \ Views \ Composers \ CatFormComposer不存在
这是我的代码: 应用\ HTTP \视图\作曲家\ CatFormComposer.php
<?php
namespace Furbook\Http\Views\Composers;
use Furbook\Breed;
use Illuminate\Contracts\View\View;
class CatFormComposer {
protected $breeds;
public function __construct (Breed $breeds) {
$this->breeds = $breeds;
}
public function compose(View $view) {
$view->with('breeds', $this->breeds->lists('name', 'id');
}
}
应用程序/提供者/ AppServiceProvider.php
<?php
namespace Furbook\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\View\Factory as ViewFactory;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot(ViewFactory $view)
{
$view->composer('partials.forms.cat',
'App\Http\Views\Composers\CatFormComposer');
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}
答案 0 :(得分:1)
您的CatFormComposer
课程已在Furbook\Http\Views\Composers
命名空间中定义,但您正在App\Http\Views\Composers
中寻找。{1}}。您需要将正确的命名空间传递给$view->composer()
调用。