How to get a route to directly show a view?

Laravel: How to get a route to directly show a view?

If you have a simple controller method that is just:

  1. public function about_me() {
  2.                 return view('static.about_me');
  3.                 }

Then you can do the following in your routes file:

  1. Route::view('/about','static.about_me');

This makes it a bit quicker to code. Sometimes it is common to end up with a bunch of functions (in a controller named something like StaticPagesController) that don't do anything apart from return a view. Using the Route::view method in your routes file means you can skip making that function.

webdevetc profile pic
webdevetc

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This (webdevetc.com) is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.



More...


Comments and discussion about How to get a route to directly show a view?

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the Laravel language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

Force trailing slash (redirect if no trailing slash exists) in .htaccess

What is the loop variable in a @foreach loop in Blade?

What is Bubble sort, and how to write an implementation of it in PHP

How to generate an array for a dropdown (with ['key' => 'value']) suitable for a dropdown, from a Laravel collection of Eloquent objects?

How to get the type of a variable in JS?

What are the SPL Iterators in PHP?

How to add the CSRF (Cross-site request forgery) token in Laravel?

How to reverse htmlentities() / What is the opposite of htmlentities()?

How to show a specific view file for certain error codes?

How do you access the php://input stream?