Ad

Blade Templating @extend Go Up A Folder

- 1 answer

Alright so I know about the Blade @extends method to enter a folder, but how about leaving one to enter another? How would that be achieved?

For example:

If my index.blade.php is in app/views and my master.blade.php (The layout file) is in app/views/layouts I use the @extends function like:

@extends('layouts.master')

Which results in the application going into the layouts folder as expected.

But now, I have the following directory structure;

app/
    views/
         errors/
               404.blade.php
         layouts/
                master.blade.php
         index.blade.php

Now what I want to do is use @extends to have the 404.blade.php extend the master.blade.php but I have no idea as to how to "go up a folder".

TL:DR How do I go up one folder in the @extends function

Regards.

Ad

Answer

@extends is relative to the root of your view directory.

So when you do @extends('layouts.master'), it will always be views/layouts/master.blade.php no matter the location of the view that is extending it.

In other words, you change nothing and just do:

@extends('layouts.master')
Ad
source: stackoverflow.com
Ad