Ad

Class Does Not Exist ErrorException In Container.php Line 738:

- 1 answer

I am learning laravel and got an error. Do you any suggestions whats wrong? I tried "composer dump-autoload" but it didn't solved this problem.

ErrorException in Container.php line 738: Class App\Http\Views\Composers\CatFormComposer does not exist (View: /Applications/MAMP/htdocs/lar/furbook.com/resources/views/cats/create.blade.php)

ReflectionException in Container.php line 738: Class App\Http\Views\Composers\CatFormComposer does not exist

Here is my code: app\Http\Views\Composers\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');
    }

}

app/Providers/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()
    {
        //
    }
}
Ad

Answer

Your CatFormComposer class is defined within the Furbook\Http\Views\Composers namespace, but you're looking for it in App\Http\Views\Composers. You need to pass the correct namespace to the $view->composer() call.

Ad
source: stackoverflow.com
Ad