0% found this document useful (0 votes)
20 views2 pages

Laravel 03

Laravel Notes

Uploaded by

waver58650
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

Laravel 03

Laravel Notes

Uploaded by

waver58650
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Laravel Routes :-

=================
1. Laravel Routing- Basic Routing and Redirect Routes :-
---------------------------------------------------------
1. What is Routing ?
--> Laravel routes are used to bind URL to controller action.
--> When you create new pages in Laravel you have to remember
three things :-
a. you first decide, what would be the URL that user will access
via browser?

b. How you can bind this URL with a specific controller methods?

c. Which view will be rendered by the controller methods?

2. Where to define Routes?


--> Routes in Laravel are defined in following location :-
a. routes/api.php --> Routes for URL predefined with /api.
b. routes/web.php --> All web routes are defined here.

3. Routing Types :-
a. Basic Routing
b. Redirect Routes
c. View Routes
d. Route Parameters
e. Named Routes
f. Route Caching

a. Basic Routing :-

Route ::get('/greeting',function(){
return "Hello World";
});

b. Redirect Routes :-
1. Route::redirect('/here','there');
2. Route::redirect('/here', '/there', 301);
3. Route::permanentRedirect('/here', '/there');

===================================================================================
===================
2. Laravel Routing - View Routes, Route Parameters, Named Routes,Route Caching :-
----------------------------------------------------------------------------------

c. View Routes :-
1. Route::view('/welcome','welcome');

2. Route::view('/welcome', 'welcome', ['name' => 'Taylor']);


display the value name in view page:- welcome.blade.php
{{$name}}

3. Route::get('/', function () {
return view('welcome');
});
d. Route Parameters :-
Route::get('/user/{name}',function($name){
return 'User : '.$name;
});

OR
Route::get('/user/{id}',function($id){
return 'User : '.$id;
});
OR
Route::get('/user/{fname}/{lname}',function($fname,$lname){
return 'User : '.$fname.' '.$lname;
});

e. Named Routes :-
Route::get('/users/profile', function () {
// ....
})->name('profile');

OR

Route::get('/users/profile',[UserProfileController::class,'show'])-
>name('profile')

f. Route Caching :-
1. php artisan route:cache
2. php artisan route:clear

===================================================================================
===================
3. Assignment : Laravel Routing :-
----------------------------------
1. Create view Routes with the URL about, contact and home.
2. Create three different views withe fake data for the said routes.
3. Create routes with parameters and pass and print the same parameter
in the views.
4. Create a routes with parameters, if Parameters value is LearnVern
then redirect the same route on learnvern.com

You might also like