Cozzbie
Cozzbie

Reputation: 1055

How to return routes to views in laravel

I just tried loading a view using a route like so:

route.php
Route::get("/page", function(){
   return View::make("dir.page");
});


controller.php
View::make("/page");

...and an error was thrown. So my question is:

Is it possible to load a route via a view and if its possible then how?

Thanks.

Upvotes: 16

Views: 59377

Answers (5)

Vishal Singh
Vishal Singh

Reputation: 31

Route::view('RouteName', 'dir.filename'); // version 6+

Upvotes: 3

Ilyich
Ilyich

Reputation: 5776

This works in Laravel 7:

Route::get("/page", function(){
   return view("dir.page");
});

Upvotes: 3

vimuth
vimuth

Reputation: 5602

In laravel 5.8 I had to use this.

Route::get("/page", function(){
   return \View::make("dir.page");
});

Upvotes: 0

Neabfi
Neabfi

Reputation: 4741

In Laravel 5.5 you can now do:

Route::view('/page', 'dir.page');

Upvotes: 21

Danny
Danny

Reputation: 454

Your should return your View.

So this will work fine:

Route::get("/page", function(){
   return View::make("dir.page");
});

Upvotes: 14

Related Questions