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.
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.
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();
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.
In Laravel 5.5 you can now do:
Route::view('/page', 'dir.page');
Your should return
your View.
So this will work fine:
Route::get("/page", function(){
return View::make("dir.page");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With