mstdmstd's avatar

How in laravel /inertia-vue3 set DifferentLayout.vue based blade file?

In laravel 8 / inertia-vue3 / vue 3 app I have 2 different layouts

resources/js/Layouts/AppLayout.vue and resources/js/Layouts/FrontendLayout.vue

But checking how they work I see they both are based on the same resources/views/app.blade.php file.

If I create new resources/views/frontend.blade.php file how can FrontendLayout.vue be bases on this frontend.blade.php ?

blade files has directive :

@extends('layouts.backend')

But I did not find such directive in inertiajs ? Are there any?

Thanks!

0 likes
2 replies
lolsokje's avatar

You have to define what layout you want to use in your Vue file, for example

<script>
import AppLayout from 'path/to/Layouts/AppLayout';

export default { layout: AppLayout };
</script>

or you can wrap your template with AppLayout or FrontendLayout tags.

piljac1's avatar
piljac1
Best Answer
Level 28

Your Vue layout cannot dictate which layout it will be rendered in, because that's simply not accomplishable. However, there are other ways to solve what you want to do.

The most common way is to override the rootView method in app/Http/Middleware/HandleInertiaRequests

public function rootView(Request $request) {
    if (/* Current request is front-end */) {
        return 'frontend';
    }

    return parent::rootView($request);
}

How you determine that a request is front-end is up to you because I don't know your structure.

1 like

Please or to participate in this conversation.