route('articles.index'); })->name('home'); // ========================================================================= // BÀI TẬP 01: ROUTING NÂNG CAO (THAM SỐ ĐỘNG, REGEX, NAMED ROUTES, GROUP) // ========================================================================= // 1.1. Route có tham số động {page} (ràng buộc chỉ nhận chữ số) Route::get('/articles/page/{page}', function (int $page) { return "Đang xem danh sách bài viết tại trang số: {$page}"; })->whereNumber('page')->name('articles.page'); // 1.2. Route có tham số tùy chọn {slug?} kèm ràng buộc biểu thức chính quy (Regex) Route::get('/articles/archive/{slug?}', function (?string $slug = 'tat-ca-bai-viet') { return "Đang tra cứu bài viết theo slug: {$slug}"; })->where('slug', '[a-z0-9-]+')->name('articles.slug'); // 1.3. Route Group với tiền tố 'admin' và đặt tên tiền tố 'admin.' Route::prefix('admin')->name('admin.')->group(function () { Route::get('/dashboard', function () { return 'Trang bảng điều khiển Quản trị viên (Admin Dashboard)'; })->name('dashboard'); Route::get('/articles', [ArticleController::class, 'index'])->name('articles'); }); // ========================================================================= // BÀI TẬP 06: ROUTE MODEL BINDING THEO SLUG (Đặt trước resource để ưu tiên) // ========================================================================= // Tự động tìm Article theo cột `slug`, trả về 404 nếu không tồn tại Route::get('/articles/slug/{article:slug}', [ArticleController::class, 'show']) ->where('article', '[a-z0-9-]+') ->name('articles.show.slug'); // ========================================================================= // BÀI TẬP 02, 05, 06, 07, 09: RESTFUL RESOURCE CONTROLLER CHO ARTICLES // ========================================================================= // Tự động sinh 7 routes chuẩn RESTful: // - GET /articles -> index (articles.index) // - GET /articles/create -> create (articles.create) // - POST /articles -> store (articles.store) // - GET /articles/{article} -> show (articles.show) [Implicit Model Binding] // - GET /articles/{article}/edit -> edit (articles.edit) [Implicit Model Binding] // - PUT/PATCH /articles/{article} -> update (articles.update) [Implicit Model Binding] // - DELETE /articles/{article} -> destroy (articles.destroy) [Implicit Model Binding] Route::resource('articles', ArticleController::class);