A wrapper for making SPA using Laravel Livewire.
- PHP 8.x or higher
- Livewire 2.x or higher
composer require rahmanramsi/livewire-spa
By default, LivewireSpa will render Page Component into the {{ $slot }}
of a blade layout component located at: resources/views/layouts/app.blade.php
You must create resources/views/layouts/app.blade.php
file first and add your custom layout there.
Add {{ slot }}
inside the body, and add the following Blade directives in the head
tag, and before the end body
tag in your template.
<html>
<head>
...
@livewireStyles
@livewireSpaStyles
</head>
<body>
{{ $slot }}
@livewireScripts
@livewireSpaScripts
</body>
</html>
php artisan vendor:publish --tag="livewire-spa-config"
This is the contents of the published config file:
return [
'path' => 'spa',
'layout' => 'layouts.app',
'single_page' => \Rahmanramsi\LivewireSpa\Http\Livewire\SinglePage::class,
'pages' => [
'default' => null,
'error' => \Rahmanramsi\LivewireSpa\Http\Livewire\Pages\ErrorPage::class,
'namespace' => 'App\\Http\\LivewireSpa',
'path' => app_path('Http/LivewireSpa'),
'register' => [],
],
'middleware' => ['web'],
'livewire' => [
'namespace' => 'App\\Http\\LivewireSpa',
'path' => app_path('Http/LivewireSpa'),
],
];
You can create a page by using the following command:
php artisan make:livewire-spa PageName
Two new files were created in your project:
app\LivewireSpa\PageName.php
resources\views\livewire-spa\page-name.blade.php
If you wish to create Page within sub-folders, you can use the following different syntaxes:
php artisan make:livewire-spa SubFolder/PageName
Now, the two created files will be in sub-folders:
app\LivewireSpa\SubFolder\PageName.php
resources\views\livewire-spa\sub-folder\page-name.blade.php
Just use default a[href]
tag, it will automatically detect it. If you don't want LivewireSpa to prevent the default behavior, just add native
attribute to a
tag.
- Write the test
- Demo Page
- Documentation Page
- Starterpack
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.