laravel / folio

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

Support non blade files #50

Closed ZebTheWizard closed 1 year ago

ZebTheWizard commented 1 year ago

There appears to be an API exposed for using Folio with a custom response Folio::renderUsing. However, if I do something like the following to render components with Inertia, it only works when I have the same directory structure in the default views/pages folder.

Folio::renderUsing(function (Request $request, MatchedView $matchedView) {
    $path = Str::between($matchedView->relativePath(), '/', '.blade.php');
    return Inertia::render($path, $matchedView->data);
});
Folio::route(resource_path('views/pages'), middleware: [
    '*' => [
        //
    ],
]);

example directory structure that successfully renders svelte components using Inertia:

/
└── resources
    ├── views
    │   └── index.blade.php
    │       └── users
    │           ├── [User].blade.php
    │           └── index.blade.php
    └── js
        └── Pages
            └── index.svelte
                └── users
                    ├── [User].svelte
                    └── index.svelte

ideally we could modify the resource path and add a value in a config file or in the service provider to tell Folio to search for svelte files instead of blade files so we could have the following directory structure instead:

/
└── resources
    └── js
        └── Pages
            └── index.svelte
                └── users
                    ├── [User].svelte
                    └── index.svelte

The setup could look something like this:

Folio::extension('svelte');
Folio::renderUsing(function (Request $request, MatchedView $matchedView) {
    return Inertia::render($matchedView->relativePath(), $matchedView->data);
});
Folio::route(resource_path('js/Pages'), middleware: [
    '*' => [
        //
    ],
]);
ZebTheWizard commented 1 year ago

see pr https://github.com/laravel/folio/pull/51

driesvints commented 1 year ago

Thanks @ZebTheWizard. Let's see how your PR goes