Laravel dynamic page title in navbar-brand

If this is your master page title below

<html>
<head>
    <title>App Name - @yield('title')</title>
</head>
<body>
    @section('sidebar')
        This is the master sidebar.
    @show

    <div class="container">
        @yield('content')
    </div>
</body>

then your page title can be changed in your blade page like below

@extends('layouts.master')

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

@section('sidebar')
@parent

<p>This is appended to the master sidebar.</p>
@endsection

@section('content')
<p>This is my body content.</p>
@endsection

More information can be found here Laravel Docs


You can pass it to a view for example

Controller

$title = 'Welcome';

return view('welcome', compact('title'));

View

isset($title) ? $title : 'title';

or php7

$title ?? 'title';

Null coalescing operator