Route in Laravel- Jagora zuwa Route da Gudanar da Buƙatun URL a ciki Laravel

Route a cikin Laravel ya ƙunshi ayyana route s don aikace-aikacen gidan yanar gizon ku da ƙayyade yadda ake gudanar da buƙatun URL masu shigowa. Tare da Laravel, kewayawa ya zama mai sauƙi da sassauƙa.

 

Don farawa, zaku iya ayyana route s a cikin routes/web.php ko routes/api.php fayil, ya danganta da nau'in aikace-aikacen da kuke haɓakawa.

Misali, zaku iya ayyana mai sauki route kamar haka:

Route::get('/about', function() {  
    return "This is the About page";  
});  

A cikin wannan misalin, lokacin da mai amfani ya shiga /about URL ɗin, Laravel zai kira aikin sarrafa daidai kuma ya mayar da kirtani "Wannan shine Game da shafi" ga mai amfani.

 

Bugu da ƙari, Laravel yana ba da wasu route hanyoyin kamar post, put, patch, delete, da sauransu, don sarrafa hanyoyin HTTP daban-daban.

Hakanan zaka iya route zuwa ga Masu Gudanarwa don ɗaukar buƙatun URL.

Misali:

Route::get('/products', 'ProductController@index');

A cikin wannan misalin, lokacin da mai amfani ya shiga /products URL, Laravel zai kira index hanyar da ke cikin ProductController don karɓar buƙatar.

 

Hakanan zaka iya amfani da maganganu na yau da kullun da sigogi masu ƙarfi don ƙarin sassauƙa route.

Misali:

Route::get('/users/{id}', 'UserController@show');

A cikin wannan misali, {id} siga ne mai ƙarfi a cikin URL kuma za a wuce shi zuwa show hanyar da ke cikin UserController don sarrafa buƙatar.

Bugu da ƙari, Laravel yana ba da ƙarin fasali kamar route ƙungiyoyi, albarkatu route, middleware da ƙari, don keɓancewa da sarrafawa route a cikin aikace-aikacen ku Laravel.

 

A taƙaice, tare da Laravel, kuna da zaɓuɓɓuka da yawa da fasali masu ƙarfi don ayyana route s da sarrafa buƙatun URL. Wannan yana ba ku damar gina aikace-aikacen yanar gizo masu sassauƙa da kiyayewa.