php artisan make:provider CategoryComposerServiceProvider
this file is located inside the app/Http/Providers as CategoryComposerServiceProvider.php
add the created provier in the config/app.php file as
'prodivers'=>[
App\Providers\CategoryComposerServiceProvider::class,
]
in the proviers/CategoryComposerServiceProvider.php file
<?php
namespace App\Providers;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
class CategoryComposerServiceProvider extends ServiceProvider
{
public function boot()
{
View::composer('layouts.menubar','App\Http\View\Composers\CategoryComposer');
//
}
}
inside app/Http/View/Composers/categoryComposer.php file
<?php
namespace App\Http\View\Composers;
use App\Category;
use App\SubCategory;
use Illuminate\View\View;
class CategoryComposer
{
public function compose(View $view)
{
// $view->with('count', $this->users->count());
$view->with('categories',Category::all());
$view->with('subcategories',SubCategory::all());
}
}

إرسال تعليق