lewis4u lewis4u - 1 month ago 14
PHP Question

Laravel - Request::is() doesn't work as it should

I have 4 different titles

users

agencies

end customers

inactive

and i have only one view (one laravel.blade.php file) with this code

@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


and in my layout i have

<title>@yield('title')</title>


and in my routes i have

Route::get('/admin/users', 'AdminController@showUsers');
Route::get('/admin/agencies', 'AdminController@showAgencies');
Route::get('/admin/endcustomers', 'AdminController@showEndCustomers');
Route::get('/admin/inactive', 'AdminController@showInactiveUsers');


And which ever site i call the title is always Inactive
What am i doing wrong....why the title doesn't change?

Answer

Well, you can't use the "Request" in the view.

I suggest you send the title from the controller like this:

return view('%the name of the view%', ['title'=>"%Your title%"]);

Then in the view, you can put this

<title> {{$title }} </title>