Host your Laravel site on Netlify, Vercel, or any other static site host. This package will generate static files from your Laravel site with very little setup. A convenient attribute is provided to provide routes with dynamic parameters.
You can install the package via composer:
composer require antlur/laravel-static-export
You can publish the config file with:
php artisan vendor:publish --tag="static-export-config"
This is the contents of the published config file:
return [
'output_path' => base_path('dist'),
'clear_before_export' => true,
];
php artisan export
When generating the static site, you can use the ExportPaths attribute to define which routes should be generated. This is useful when you have dynamic data that you want to generate static pages for. For example, if you have a blog and you want to generate static pages for each blog post, you can use the ExportPaths attribute to define which routes should be generated. The rest of your logic can be handled as if it was a normal Laravel application.
// web.php
Route::get('/blog/{slug}', [BlogController::class, 'show']);
// app/Http/Controllers/BlogController.php
use Antlur\Export\Attributes\ExportPaths;
class BlogController
{
// You can pass a class that implements PathProvider
#[ExportPaths(BlogPostPaths::class)]
public function show(string $name)
{}
// Or you can pass an array of paths directly
#[ExportPaths(['/blog/first-post', '/blog/second-post'])]
public function show(string $name)
{}
}
// app/PathProviders/BlogPostPaths.php
class BlogPostPaths implements \Antlur\Export\Contracts\PathProvider
{
public function paths(): array
{
return [
'/blog/first-post',
'/blog/second-post',
];
}
}
composer test
Please see CHANGELOG for more information on what has changed recently.
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.