In general, there are two main ways to use Livewire:
- You build the full project with Laravel Controllers, and use Livewire only for small dynamic elements on the pages
- You use Livewire Components instead of Laravel Controllers, with so-called Full-Page Components
The choice is yours, it's a personal preference. In this lesson, let's see how to do it with full-page components.
Routes
Instead of mapping to the Controller in the Routes files, you just need to map directly to the Livewire component.
use App\Livewire\CreatePost; Route::get('/posts/create', CreatePost::class);
Layout Files
Livewire uses Blade component as an application layout. So it needs to have a {{ $slot }} placeholder. By default, Livewire uses...
If we are using resources/views/components/layouts/app.blade.php as global layout
then the config/livewire.php should read
Yes, but you don't necessarily have to have this config, as it is the DEFAULT value.
Quote from the docs: "By default, Livewire will automatically look for a layout file named: resources/views/components/layouts/app.blade.php"
I’m sorry but in my version Laravel/framework 10.35.0 and laravel/breeze 1.26.2 with livewire/livewire 3.3.0 Out of the box Laravel puts the layouts in its one directory. Resources/views/layouts/app.blade.php
Not in resources/views/components/layouts/app.blade.php.
However if you create a new layout using the php artisan make:component AppLayout command it will put the file in the components directory but not in a layouts subdirectory in less you tell it to.
PS. under the latest “Laravel new” you can get Breeze to setup using livewire 3 and the old problems with Alpin.js has been taken care of.
I have the same issue! My app layout is in 'resources/views/layouts/app.blade.php' - What was your workaround for this, Richard? Did you just update the livewire config file to use layouts.app.blade?
Please read the docs about layouts https://livewire.laravel.com/docs/components#layout-files