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
119 stars 19 forks source link

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

Closed d0004 closed 1 month ago

d0004 commented 2 months 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 2 months 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!