Home > database >  how to make dynamic title on laravel by fetching the data from a list of data on the backend
how to make dynamic title on laravel by fetching the data from a list of data on the backend

Time:02-26

how do I make Title dynamic in the product detail page from the data from the backend in laravel

like an I have a list of cities, under the cities, there is a bunch of laundries. On the main page, we can search for cities so the list of cities is shown from the database. when the user clicks any of the cities the page will be directed to another page with a list of laundries so I want the title to be laundries in {{ city name }} same way when the user clicks on any laundry the page is directed detail page of laundries so the title I want to be {{ laundry name }} in {{ city name }}

CodePudding user response:

You can use JS for it

Simply

 document.title = newTitle;

CodePudding user response:

You can set @yield for title via template inheritance.

Layout

<html>
    <head>
        <title>@yield('title')</title>
    </head>
    <body>
    ...

Set $dynamicTitle in view :

@extends('layouts.app')
 
@section('title', $dynamicTitle)
 
@section('content')
    ...
@endsection

You are free to assign a value to the @section('title') using $dynamicTitle or $item->title for example. Depends on your needs.

  • Related