Định tuyến (Routing) trong Laravel
- Định tuyến cơ bản
- Định tuyến các tham số
- Các định tuyến đặt tên
Định tuyến cơ bản

Route::get('/', function() {return view('welcome');});
Ví dụ
routes/web.php
return view('welcome');
});
resources/view/welcome.blade.php
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet">
<!-- Styles -->
<style>
html, body {
background-color: #fff;
color: #636b6f;
font-family: 'Nunito', sans-serif;
font-weight: 200;
height: 100vh;
margin: 0;
}
.full-height {
height: 100vh;
}
.flex-center {
align-items: center;
display: flex;
justify-content: center;
}
.content {
text-align: center;
}
.title {
font-size: 84px;
}
.m-b-md {
margin-bottom: 30px;
}
</style>
</head>
<body>
<div class="flex-center position-ref full-height">
<div class="content">
<div class="title m-b-md">
Laravel
</div>
</div>
</div>
</body>
</html>


Định tuyến các tham số
Các tham số bắt buộc
Route::get('ID/{id}',function($id) {
echo 'ID: '.$id;
});
Các tham số tùy chọn
Route::get('user/{name?}', function ($name = 'LearnSkill') { return $name;});
Các định tuyến đặt tên
Route::get('user/profile', 'UserController@showProfile')->name('profile');UserController sẽ gọi hàm showProfile với tham số là profile. Các tham số sử dụng phương thức name vào định nghĩa routes.