Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 680
Cozzbie Avatar asked Sep 28 '14 15:09

Cozzbie


People also ask

How do I return a view in Laravel?

Views may also be returned using the View facade: use Illuminate\Support\Facades\View; return View::make('greeting', ['name' => 'James']); As you can see, the first argument passed to the view helper corresponds to the name of the view file in the resources/views directory.

How do I redirect back in Laravel?

If you just want to redirect a user back to the previous page (the most common example - is to redirect back to the form page after data validation failed), you can use this: return redirect()->back();

How do I return a response in Laravel?

Laravel provides several different ways to return response. Response can be sent either from route or from controller. The basic response that can be sent is simple string as shown in the below sample code. This string will be automatically converted to appropriate HTTP response.


2 Answers

In Laravel 5.5 you can now do:

Route::view('/page', 'dir.page');
like image 111
Neabfi Avatar answered Nov 02 '22 00:11

Neabfi


Your should return your View.

So this will work fine:

Route::get("/page", function(){
   return View::make("dir.page");
});
like image 38
Danny Avatar answered Nov 02 '22 00:11

Danny