Defining Basic Routes in Laravel

Routes handle the URL mapping of your application to a specific function or code. Routes URI can either be mapped to a inline function defined or to a controller method.

In Laravel 5.5 , Most of the web related routes are defined in web.php file under routes folder

Defining a Route with Closure function.

A very simple route can return a string directly from the closure function.

Route::get('foo', function () {
    return 'Hello World';

Defining a Route that returns a view

You can return a view file. In the code given below when user will hit the /about url of your application. Application will render the content of view about.blade.php in browser.

Route::get('about', function () {
    return view('about');

Defining a Route that trigger’s Controller Method.

You can define a route that trigger’s a specific method in your controller. For example in the below code when user hits /user url in the browser it will execute index method of UserController. index method can be used to simple return a view along with some logic that needs to be performed before something is returned to the user.

Route::get('/user', 'UsersController@index');


Related Articles

Site Footer