statikbe / laravel-filament-flexible-content-blocks

The Laravel Filament Flexible Content Blocks package helps you to easily create content in Filament for any model, with predefined or custom blocks, and foreach block an extendable Blade view component.
MIT License
111 stars 18 forks source link

Empty slug for routes like /en for home page #45

Open d0004 opened 3 weeks ago

d0004 commented 3 weeks ago

I need to create home page using TranslatablePageResource with url like /en or /ru How i can do it? I already tried to create my own SlugField without required flag but when I save page with empty slug, it is generated automatically. Maybe there are other more correct ways to create home page? Because in example project home page is just standard Laravel welcome page.

sten commented 1 day ago

@d0004 I typically add a code field to the page. Then I set my home page with a code (e.g. 'HOME').

Then I make a HomeController with a route with your localization middleware to get the locale on the route. In the HomeController you can just query the page with the code 'HOME'. Something like (untested ;-)):

class HomeController extends Controller 
{
     public function index()
     {
           $page = Page::code('HOME')->firstOrFail();

           return view('your_page_view', ['page' => $page]);
     }
}

I hope this helps!