Defining Basic Routes in Laravel

Defining Basic Routes in Laravel

 

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 an inline function defined or to a controller method.

In Laravel, Most of the web related routes are defined in the web.php file under the 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. The application will render the content of view about.blade.php in the browser.

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

Defining a Route that triggers’s Controller Method.

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

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

Post a Comment

0 Comments

close