Routing

Sprnva has a beautiful routing built in. Route is our traffic control of our application that tells the entire application which page to be loaded when we hit a certain url.

You will find the routes at config/routes/web.php. Then this is how you declare a basic route.

Route::get('/uri', ['Controller@method', ['middleware']]);

/uri - the route you want to define.

['Controller@method', ['middleware']] - the action of the /uri

middleware - handles the protection of our routes basically our guardians.

Middleware Present:

  • auth : is the route guardian to protect your routes from direct access in the URL without authentication. If not specified the route will be accessible without authentication.

Sprnva routing supports this following methods:

Route::get($uri, $action);
Route::post($uri, $action);
Route::put($uri, $action);
Route::patch($uri, $action);
Route::delete($uri, $action);
Route::options($uri, $action);

This is what a basic route look like:

// routes is accessible without authenticating
Route::get("/register", ['RegisterController@index']);
Route::post("/register", ['RegisterController@store']);

// routes is accessible only if authenticated
Route::get("/profile", ['ProfileController@index', ['auth']]);
Route::post('/profile', ['ProfileController@update', ['auth']]);

where profile route is protected by middleware auth. It means you cannot access this route directly in the URL without authenticating.

Last updated