There are two types of routing in Laravel →
- Api routing → API-related routing
- Web routing → Web Interface related routing → Web middleware(give all session features).
The route has used two parameters →
- URL
- 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:
- Get ( When we want to fetch any content then we will use the get method )
- Post (When we want to store data in the database, then we will use the post method)
- Put (When we want to update our data in the database then we will use the put method.)
- Patch (When we want to update a single field in the database, then we will use the patch method)
- Option (When will need optionis determined for the request and response, then we will usethe option method)
- Delete (When we want to delete any content then we will use the delete method)
- group(backslash not type)