namespace App\Http\ViewComposers; use Illuminate\View\View; class NavigationComposer { public function compose(View $view) { $menu = [ 'Home' => '/', 'Products' => '/products', 'About Us' => '/about', 'Contact Us' => '/contact', ]; $view->with('menu', $menu); } }
namespace App\Providers; use Illuminate\Support\ServiceProvider; use App\Http\ViewComposers\NavigationComposer; class AppServiceProvider extends ServiceProvider { public function boot() { view()->composer('partials.navbar', NavigationComposer::class); } }
namespace App\Http\ViewComposers; use Illuminate\View\View; class MetaTagsComposer { public function compose(View $view) { $title = $view->title ?? config('app.name'); $keywords = $view->keywords ?? config('app.keywords'); $description = $view->description ?? config('app.description'); $view->with([ 'title' => $title, 'keywords' => $keywords, 'description' => $description, ]); } }
@extends('layouts.app') @section('content')The package/library used here is Laravel, specifically the `illuminate/view` package which provides the View class and related functionality used by the examples.My Page
@endsection @section('meta') @include('partials.meta', [ 'title' => 'My Page', 'keywords' => 'my, page', 'description' => 'This is my page', ]) @endsection