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.
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...
Can you show us your tasks/index.blade.php file?
@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
I have a pb to paste the code in the post, how can I put it in "raw mode"?
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>
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.
Hi @sr57
Are you using livewire or traditional blade?
@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>
@sr57 why did you mark your own post as the best answer?
Did my suggestion in the last post fix the issue?
Thanks for your time & answer but as I wrote in my best answer I had nothing more to test.
Please sign in or create an account to participate in this conversation.