Home > front end >  Laravel 8 'Undefined variable: pageTitle' on a controller variable
Laravel 8 'Undefined variable: pageTitle' on a controller variable

Time:11-21

I created a variable in my controller so I can inject a Page Title to my pages. I have other variables setup exactly the same way and they work, but for some reason I am getting an Undefined variable: pageTitle on the new variable.

ShowUsers.php

public function render()
{
    ...

    return view('livewire.show-users', [
        'users' => $query->with('documents')->paginate($this->perPage),
        'currentUser' => auth()->user(),
        'pageTitle' => 'Users',
    ]);
}

page-header.blade.php

...

<h1 class="ml-3 text-2xl font-bold leading-7 text-gray-900 sm:leading-9 sm:truncate">
    {{ $pageTitle }}
</h1>

...

CodePudding user response:

You are not binding variable pageTitle into the page-header blade file. You can bind variables using Laravel Blade.

liveware/show-users.blade.php

@extends('page-header', ['pageTitle' => 'Users']) 

CodePudding user response:

Are other variables accessible in blade ?

  • Related