Membuat Global Variable di Laravel
buat folder composers di dalamfolder app
buat file di app/composers dengan nama NavbarComposer.php
buat file di app/composers dengan nama NavbarComposer.php
<?php /** * */ namespace App\Composers; use Illuminate\Contracts\View\View; use App\Models\Incompatibility; class NavbarComposer{ public function compose($view){ $incompatibilities=Incompatibility::where('status','=',NULL)->get(); $view->with('incompatibilities',$incompatibilities); } } ?>Terus edit file AppServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$this->buatNavbar();
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->bind('user','App\Models\User');
}
private function buatNavbar(){
view()->composer('backend.layout.app','App\Composers\NavbarComposer');
}
}
0 comments: