Introductions to routes in Laravel

There are two types of routing in Laravel →

  1. Api routing → API-related routing
  2. Web routing → Web Interface related routing → Web middleware(give all session features).

The route has used two parameters →

  1. URL
  2. Callback functions

Example →

Route::get('/url_address',function(){
return view('name_ofview');
});
Route::get('/test',function(){
return "This is test page";
});

Example → Pass parameter through URL with validations (Dynamics Route)

Route::get('/cse/{id}',function($id){
return "This is cse student and the id is".$id;
});
Route::get('/cse/{id}',function($id){
return "This is cse student and the id is".$id;
})->where('id','[0–9]+');

Method training

Example → Pass optional parameter through URL with validations (Dynamics Route)

Route::get('/student/{id}/{name?}',function($id,$name="Ruman"){
return "Your id is ".$id." and your name is ".$name;
})->where('id','[0–9]+');

Example → We can give a name for route → user-define → return URL of route

Route::get('/login',function(){
return "This is login page";
})->name('login');
Route::get('/return-route-url',function(){
return route('login');
//its print the login route url });

Route has 6 methods:

  1. Get ( When we want to fetch any content then we will use the get method )
  2. Post (When we want to store data in the database, then we will use the post method)
  3. Put (When we want to update our data in the database then we will use the put method.)
  4. Patch (When we want to update a single field in the database, then we will use the patch method)
  5. Option (When will need optionis determined for the request and response, then we will usethe option method)
  6. Delete (When we want to delete any content then we will use the delete method)
  7. group(backslash not type)

Leave a Reply

Your email address will not be published. Required fields are marked *