Specifically, I want one class, or method, to be taking care of what's going to be in my <title>
tag in app.blade.php file (the file included on every page).
CodePudding user response:
You can do this with laravel sessions, firstly you can add a session variable lets say on login like this
Session::put('title', $value);
Now you can change this every time you switch the page via controller, just add this to every request and change the title as you please, and finally in your blades you can just do this
<title>{{ Session::get('title') ?? 'Login' }}</title>
CodePudding user response:
Generally, I use this:
In my app.blade.php
<title> {{ $title ? $title.' - ' ? '' }} website-name </title>
And in the controller files
I used to return the $data
array instead of the compact method:
$data['title'] = 'My title';
return view('view.name', $data);
This will automatically consider the title if you add it to your controller else it will display the website name. No need to add the "<title>" tag in every blade file.