I want to implement dynamic titles, meta descriptions, and canonical tags in header.blade.php. Additionally, I want to make this implementation flexible so that I can add more SEO-related tags in the future.
I want to pass this data from the controller to make it dynamic. What is the best way to achieve this, and are there any other options I should consider for more flexibility in handling additional tags?
@bishtyogeshsingh I’d personally create some sort of singleton “metadata bag” that you can set keys on in your controllers (or elsewhere), and then display them in another location (such as your layout component).
public function someAction()
{
Metadata::set('title', 'Page Title');
Metadata::set('description', 'Page meta description.');
// Return response...
}
Late to the party, but have you tried adding a section in your layout like @yield('meta') and then letting each page push in its own tags with @section('meta')? That keeps your components clean and still lets every view set custom SEO data. Curious how you're handling dynamic titles right now—using a component, a helper, or just sections?