WEB DEVELOPER SITE
TUTORIALS HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Laravel - Routing


Laravel - Routing :

Laravel, all solicitations are mapped with the assistance of courses. Fundamental directing courses the demand to the related controllers.

Routing in Laravel incorporates the accompanying classes −

  • Basic Routing
  • Route parameters
  • Named Routes

Basic Routing

All the application courses are enlisted inside the app/routes.php document. This record tells Laravel for the URIs it ought to react to and the related controller will give it a specific call. The example course for the appreciated page can be viewed as appeared in the screen capture given underneath app/Http/routes.php

<?php 

Route::get('/', function () { 

return view('welcome'); 

});

resources/see/welcome.blade.php

Step 1 − Initially, we ought to execute the root URL of the application.

Step 2 − Now, the executed URL should coordinate with the fitting strategy in the route.php document. In the present case, it should coordinate the technique and the root ('/') URL. This will execute the related function.

Step 3 − The capacity calls the layout document resources/sees/welcome.blade.php. Next, the capacity calls the view() work with contention 'welcome' without utilizing the blade.php.

Route Parameters

Often in the application, we plan to catch the parameters go with the URL. To do this, we have to alter the code in routes.php record in like manner. There are two different ways by which we can catch the parameters go with the URL.

You can catch the parameters in routes.php record in two different ways as examined here −

Required Parameters

These parameters are those which ought to be compulsorily caught for steering the web application. For instance, it is vital to catch the client's ID number from the URL. This can be conceivable by characterizing course parameters as appeared underneath −

Discretionary Parameters In some cases designers can create parameters as discretionary and it is conceivable with the incorporation of ? after the parameter name in URL. It is critical to keep the default esteem referenced as a parameter name. Take a gander at the accompanying precedent that tells the best way to characterize a discretionary parameter −
  • Route::get('user/{name?}', work ($name = 'Welookups') { return $name;});
  • The model above checks if the esteem matches to Welookups as needs be courses to the characterized URL.