Getting inertia to use a different app file I've got inertia installed and working. What I would like to know is if there is a way to tell inertia to use a different app.blade.php.
So what I mean is instead of having the resources/views/app.blade.php I would like for it to be resources/views/layouts/app.blade.php
From Inertia docs:
By default the Laravel adapter will use the app.blade.php view. This template should include your assets, as well as the @inertia directive. If you'd like to use a different root view, you can change it using Inertia::setRootView().
https://inertiajs.com/server-side-setup#root-template
So in a service provider, for example in your AppServiceProvider add this to its boot method:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Inertia\Inertia;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Inertia::setRootView('layouts.app'); // <<<<< ADDED
}
}
Hope this helps.
@rodrigo.pedra hI! how about if I want to use 2 blades.. I got this system that I am about to create, and the page is for customers and the other page is for admin... how do I create 2 blades? for specific purposes?
@BroJenuel please make a new thread so we don't spam the original author :)
@BroJenuel I put this on my HandleInertiaRequests
protected $externalRootViewList = [
'home',
'login',
];
/**
* Handle the incoming request.
*
* @param \Illuminate\Http\Request $request
* @param Closure $next
* @return \Symfony\Component\HttpFoundation\Response
*/
public function handle(Request $request, Closure $next)
{
$route = Route::currentRouteName();
if (in_array($route, $this->externalRootViewList)) {
$this->rootView = "external";
}
return parent::handle($request, $next);
}
Most apps have multiple layouts.
How we can use them with inertia ?
For example :
A site can have guest, admin, auth (for login, register etc pages) layouts.
How we can switch these layouts ?
I have used
Inertia::setRootView('dashboard');
in controller before render function of inertia but it doesn't work.
That's why you are supposed to use app template only to include the scripts and some set up, then you can create your guest, admin, auth, and so layouts and include them in Vue with the "layout" option
import GuestLayout from '@/Layouts/Guest'
export default {
layout: GuestLayout,
...
}
it's just like using blade @extends in Livewire.
Hope this helps
Please sign in or create an account to participate in this conversation.