我有4个不同的标题
用户机构终端客户
活动
和我只有一个视图(一个laravel.blade.php文件)与这段代码
@section('title')
@if (Request::is('/admin/users'))
Alle Benutzer
@elseif(Request::is('/admin/agencies'))
Agenturen
@elseif(Request::is('/admin/endcustomers'))
Endkunden
@else
Inactive
@endif
@endsection
在我的布局中我有
<title>@yield('title')</title>
在我的路由中有
Route::get('/admin/users', 'AdminController@showUsers');
Route::get('/admin/agencies', 'AdminController@showAgencies');
Route::get('/admin/endcustomers', 'AdminController@showEndCustomers');
Route::get('/admin/inactive', 'AdminController@showInactiveUsers');
而我称之为标题的网站总是处于非活动状态我做错了什么....为什么标题不改?
你不能在视图中使用"Request"
我建议你像这样从控制器发送标题:
return view('%the name of the view%', ['title'=>"%Your title%"]);
然后在视图中,你可以放入这个
<title> {{$title }} </title>
您必须在@section中返回标题。
@section('title')
@if (Request::is('/admin/users'))
echo("Alle Benutzer");
@elseif(Request::is('/admin/agencies'))
echo("Agenturen");
@elseif(Request::is('/admin/endcustomers'))
echo("Endkunden");
@else
echo("Inactive");
@endif
@endsection
可以在Blade (view):
中这样做@switch('Route::current()->getName())
@case('/admin/users')
Alle Benutzer
@break
@case('/admin/agencies')
Agenturen
@break
@case('/admin/endcustomers')
Endkunden
@break
@default
Inactive
@endswitch