Routes - Icybrew/Stackoverflow-documentation GitHub Wiki

Routes

Like in many frameworks, to create a page, first we need to create a route for it (like a road in real life) which tells our applications router class what controller to load and which method to call.

We do that by going to config/routes.php and writing them here for easy management.

Route::get('URL', 'ControllersName@MethodsName');

Example

Route::get('/home', 'HomeController@index'); // http://localhost/home
Route::post('/home', 'HomeController@update'); // http://localhost/home

Don't forget about which request method you write!

Router::get
Router::post

/* These routes require hidden _method field in forms to be passed */
Router::patch
Router::put
Router::delete

Route variables

Routes also support dynamic variables which you can use from within called method.

Example

/* Routes.php */
Route::get('/home/{RandomName}', 'HomeController@index'); // http://localhost/home/<anything>


/* HomeController */
public function index($var) {
    echo $var;
}

⚠️ **GitHub.com Fallback** ⚠️