4

In my laravel website all pages having same title meta but how to make different title for each page please tell me.

this is my code for dynamic showing in all the pages

<title>{{setting('site.title')}} | {{setting('site.description')}}  @if(isset($data->title)) {{$data->title}} @endif</title>

file name is layouts/app.blade.php

Jignesh Joisar
  • 13,720
  • 5
  • 57
  • 57
Srashti sharma
  • 57
  • 1
  • 1
  • 5

5 Answers5

14

Inside your app.blade.php, in the head section. change:

<title>{{ config('app.name', 'Laravel') }}</title>

to:

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

You can choose any name/title that seems fitting. For other views.blade.php pages,(extending app.blade.php) you can add a title this way:

@section('title','My Title')

this comes after @extends('layouts.app')

Alessio
  • 3,404
  • 19
  • 35
  • 48
raz tsfaty
  • 141
  • 1
  • 2
11

You can specify different title for different views.

In you common header file make your title like this:

<title>@yield('page_title', 'Default Title')</title>

Then in your view file change the title to whatever you want it to be set in following way:

@section('page_title')
    {{ "Your Title" }}
@endsection
Kamal Paliwal
  • 1,251
  • 8
  • 16
2

Simply inside your app.blade.php Put this: @yield('title')

In other pages just extend the layout and put the new title at the this section

@extends('layoutWhateverYouNamedIt')

@section('title') Type your title here @endsection

Xhuljo
  • 689
  • 6
  • 12
1

Inside your app.blade.php,

<head>
  @yield('title')
  ... // other scripts
</head>

For other pages which user app.blade.php you can use it like after extending app.blade.php :

@section('title')
    <title> Your Page Title Here  </title>
@endsection`

Hope it helps. happy coding.

BlackPearl
  • 2,532
  • 3
  • 33
  • 49
Kul
  • 198
  • 1
  • 11
1

in your controller

    public function aboutUs()
    {
        //page title
        $title = 'Project | About Us';
        return view('project.about_us', compact('title'));
    }

for your view page

<title>{{ $title }}</title>
It's VIN
  • 152
  • 7