<?php
...
class UserContoller extends Controller
{
public function index()
{
return view('user', ['name' => 'foo']);
}
}
<div>
{{ $name }}
</div>
php artisan make:middleware
<?php
...
public function handle(Request $request, Clousure $next)
{
view()->share('name', 'foo');
return $next($request);
}
<?php
...
public function handle(Request $request, Clousure $next)
{
$request->attributes->add(['name' => 'foo']);
return $next($request);
}