Pierre Lartigau
Pierre Lartigau

Reputation: 197

Laravel view in a directory, not found

I'm using Laravel 5, views are locate to ressources/views/<view>.
I want to do something like ressources/views/<directory>/<views>, putting views in another level of directory (because I have a lot of them, and I want to store them in parts).
I created dorectories, then changed the Controller return, to something like return view('directory1/view1');, but view1 is not found.
It might be on the controller side that I need to correct something, but I don't really know...

Upvotes: 1

Views: 2666

Answers (3)

Saroj
Saroj

Reputation: 1373

Lets say you have a blade template in resources/views/directory1/view1.blade.php

and you want to access view1.blade.php

then in controller you just need to write

return view('directory1.view1);

If you have another blade template in resources/views/directory1/sub_directory1/view1.blade.php

then you need to write

return view('directory1.sub_directory1.view1');

Upvotes: 5

Pierre Lartigau
Pierre Lartigau

Reputation: 197

Ok, i learnt about templates, and how a view extends from a templates.
@extends('template1') isn't a "relative" path, from what I expected, it search for the template at the root view directory (ressources/views/), so i had to write @extends('directory1/template1') instead... now it can find the templates, that is next to my view file.
It confused me when i found out, because i though at the first place that the view file would search relatively to its own place, but that's not the case. ^^

Upvotes: 0

Danyal Sandeelo
Danyal Sandeelo

Reputation: 12391

use it as

 directory.inner_directory.view_name

I have created event directory and it has a file homepage.blade.php so I would call it as

return view('event.homepage', $dataArray);

Upvotes: 0

Related Questions