ignaaaam's avatar

Undefined variable $slot in blade components on a Livewire 3 project

Hello i'm doing a Laravel + Livewire 3 project but i'm having a headache with Blade components I dont know why the $slot on my app.blade.php isn't working. Tried to use the layout/extends on Livewire component but it seems i'm doing something wrong, should be mandatory to use layout/extends on my Livewire component, in another project using Livewire 3 (but using Volt instead) it wasn't necessary.

app.blade.php

dashboard.blade.php

<x-layouts.app>
    <div class="bg-gray-100 shadow-md container mx-auto p-4">
        <h1 class="text-2xl font-bold mb-4">DASHBOARD</h1>
        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
            @foreach($categories as $category)
            <livewire:category-card :category="$category"
                                    :key="$category->id" />
            @endforeach
        </div>
    </div>
    <x-layouts.app>

Dashboard livewire component

<?php

namespace App\Livewire;

use Livewire\Component;
use App\Models\Category;
use Livewire\Attributes\Layout;

class Dashboard extends Component
{
    public function render()
    {
        $categories = Category::all();
        return view('livewire.dashboard', [
            'categories' => $categories
        ]);
    }
}

livewire config file

My app.blade file is in views/components/layouts tried following the Livewire documentation for layout files but i'm missing something or doing something wrong.

0 likes
2 replies
gych's avatar

In dashboard.layout.php you have <x-layouts.app> at the end, change it to </x-layouts.app>

ignaaaam's avatar

@gych Oh sorry was testing why wasn't working and misspelled. But it's not this what's causing the error, fixed that typo and still not working.

Please or to participate in this conversation.