Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sr57's avatar
Level 39

Undefined variable: header (View: /var/www/html/Laravel/Laravel8/resources/views/layouts/app.blade.php)

Hi All;

I setup a first project in Laravel 8 with jetstream : laravel new proj --jet --stack=livewire

Then I created a crud model Task : php artisan make:model Task -a

I setup the new table migration, migrated and setup route, controller and index.blade.php template.

When I open the link : http://127.0.0.1:8000/tasks I get the error : Undefined variable: header (View: /var/www/html/Laravel/Laravel8/resources/views/layouts/app.blade.php)

I don't find the cause of this error and did not fin a way to debug.

Thanks in advance for any help.

0 likes
14 replies
ollie_123's avatar

Hey @sr57

Try putting the following at the top of your blade file:-

<x-app-layout>
    <x-slot name="header">
        <h2>Page Titel</h2>
    </x-slot>
</x-app-layout>

// The rest of your code...

sr57's avatar
Level 39

@extends('layouts.app')

@section('content')

All Tasks

@foreach($tasks as $task) {{$task->title}}

                <div class="card-body">
                    {{$task->description}}
                </div>
            </div>
            @endforeach
        </div>
    </div>
</div>

@endsection

sr57's avatar
Level 39

I have a pb to paste the code in the post, how can I put it in "raw mode"?

IlijaTatalovic's avatar

Try like this:

<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            {{ __('All Tasks') }}
        </h2>
    </x-slot>

// your content

</x-app-layout>

sr57's avatar
sr57
OP
Best Answer
Level 39

It's my first test with Laravel and I took Laravel 5 example with a Laravel 8 project. Ok (till now) with the goof example.

ollie_123's avatar

@sr57 Ah cool, in which case... presuming you have the following in app.blade

<header class="bg-white shadow md:border-b border-gray-100">
    <div class="mx-auto py-6 px-4 sm:px-6 lg:px-8">
        {{ $header }}
    </div>
</header>

use this in your component....

<x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            {{ __('Your Page Title') }}
        </h2>
</x-slot>
ollie_123's avatar

@sr57 why did you mark your own post as the best answer?

Did my suggestion in the last post fix the issue?

sr57's avatar
Level 39

Thanks for your time & answer but as I wrote in my best answer I had nothing more to test.

Please or to participate in this conversation.