I am using Laravel 8
and I have installed InertiaJS
, but in my directory resources/views/
I have a single file called index.blade.php
which I plan to use with InertiaJS
.
By default, InertiaJS
looks for a file inside that directory called app.blade.php
. I know writing the following statement:
\Inertia\Inertia::setRootView('index');
Change the rootView
and allow me to use the file I have created. It may seem like a stupid question, but as far as I see it, I can do 2 things ..
index.blade.php
to app.blade.php
ServiceProviders
that I haveI wonder the following:
InertiaJS-Laravel
does not allow publishing a ServiceProvider
with the command php artisan vendor:publish
? (the output of this command does not show me anything to publish regarding this package)
ServiceProvider
like: php artisan make:provider InertiaServiceProvider
and then register it?ServiceProvider
that already exist? Like in app/Http/Providers/RouteServiceProvider.php
What do you recommend that would be better?
I want to seek the largest possible organization in my project. Thank you very much in advance...
Update; after my initial answer (on 20-09-2020), Inertia introduced middleware to handle your Inertia requests.
As described in the answers below, you can use the command php artisan inertia:middleware
to generate this middleware. You can set the root index with:
// Set root template via property
protected $rootView = 'app';
// OR
// Set root template via method
public function rootView(Request $request)
{
return 'app';
}
You can find more info in the docs.
Replace in the App\Http\Middleware\HandleInertiaRequests
protected $rootView = 'app';
with:
public function rootView(Request $request): string
{
if ($request->route()->getPrefix() === '/admin') {
return 'admin.app';
}
return 'app';
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With