laravel / folio

Page based routing for Laravel.
MIT License
568 stars 46 forks source link

allow custom route registrar action for volt #98

Closed jdion84 closed 1 year ago

jdion84 commented 1 year ago

right now when we use folio with volt we must add @volt directive and <x-layouts.app> tag to our full page components, e.g.:

<x-layouts.app>
    @volt
        <h1>hello world</h1>
        <button wire:click="incrementCount">increment count</button>
    @endvolt
</x-layouts.app>

when registering full page components directly with volt, we use the Volt::route method:

Vote::route('/', 'index');

when we do it this way, we do not need to use the @volt directive or the layout tag in our view:

<div>
    <h1>hello world</h1>
    <button wire:click="incrementCount">increment count</button>
</div>

what if we could simply specify this class & method via the Folio registrar?:

Folio::path(resource_path('views/pages'))
    ->action([Volt::class, 'route']) 
    ->middleware([
        '*' => [
            //
        ],
    ]);

or even add a new method to Folio that uses an abstraction for volt:

Folio::path(resource_path('views/pages'))
    ->volt()
    ->middleware([
        '*' => [
            //
        ],
    ]);

this way all our folio pages will be interactive without requiring additional directive, and would also use the default livewire layouts.app component.

i can submit PR if you're interested

thoughts?

nunomaduro commented 1 year ago

Well, I'm thinking if the @volt directive isn't there and there's no body tag in the template, maybe we automatically add the default layout. We'd then use @volt on the default slot of that layout instead of using something like ->action([Volt::class, 'route']) or ->volt().

I'm not sure about this yet, but go ahead and make a sample (POC) with this idea, and we'll see where to go from there.

nunomaduro commented 1 year ago

If eventually you do a pull request, we can follow the issue from there.