3
votes

i created a new folder ViewComposers and added a new file ViewComposer.php. Path = App/Http/ViewCompers/ViewComper.php

Below is my code

<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class ViewComposer extends ServiceProvider{
     public function boot(){
            view()->composer('*', function (View $view) {
             $view->with('new_thread_comment_count', '50');
     });
}

and in my config\app.php i have added

'App\Providers\ViewComposer',

and i have also run composer dump-autoload. But i still received FatalErrorException in ProviderRepository.php line 146: Class 'App\Providers\ViewComposer' not found.

Did i miss out anything?

1
what is the path of the ViewComposer class file ?Moppo
hi...App/Http/ViewCompers/ViewComper.phpDarren Lau

1 Answers

2
votes

The app folder is PSR-4 so the namespace of the class should reflect the class file path:

//set this namespace
namespace App/Http/ViewComposers;

use Illuminate\Support\ServiceProvider;

class ViewComposer extends ServiceProvider{
     public function boot(){
            view()->composer('*', function (View $view) {
             $view->with('new_thread_comment_count', '50');
     });
}

and, in config\app.php:

'App\Http\ViewComposers\ViewComposer',