[ 'title' => 'Danh sách Bài viết (articles.index)', 'route_call' => "route('articles.index')", 'generated' => '/articles', 'breadcrumbs' => [ ['label' => 'Trang chủ', 'route' => "route('home')", 'url' => '?page=articles.index'], ['label' => 'Danh sách bài viết', 'route' => null, 'url' => null], ], ], 'articles.create' => [ 'title' => 'Tạo Bài viết mới (articles.create)', 'route_call' => "route('articles.create')", 'generated' => '/articles/create', 'breadcrumbs' => [ ['label' => 'Trang chủ', 'route' => "route('home')", 'url' => '?page=articles.index'], ['label' => 'Bài viết', 'route' => "route('articles.index')", 'url' => '?page=articles.index'], ['label' => 'Tạo bài viết mới', 'route' => null, 'url' => null], ], ], 'articles.show' => [ 'title' => 'Xem Chi tiết Bài viết #1 (articles.show)', 'route_call' => "route('articles.show', \$article)", 'generated' => '/articles/1', 'breadcrumbs' => [ ['label' => 'Trang chủ', 'route' => "route('home')", 'url' => '?page=articles.index'], ['label' => 'Bài viết', 'route' => "route('articles.index')", 'url' => '?page=articles.index'], ['label' => 'Làm chủ Laravel Routing nâng cao', 'route' => null, 'url' => null], ], ], 'articles.edit' => [ 'title' => 'Chỉnh sửa Bài viết #1 (articles.edit)', 'route_call' => "route('articles.edit', \$article)", 'generated' => '/articles/1/edit', 'breadcrumbs' => [ ['label' => 'Trang chủ', 'route' => "route('home')", 'url' => '?page=articles.index'], ['label' => 'Bài viết', 'route' => "route('articles.index')", 'url' => '?page=articles.index'], ['label' => 'Làm chủ Laravel Routing nâng cao', 'route' => "route('articles.show', \$article)", 'url' => '?page=articles.show'], ['label' => 'Chỉnh sửa', 'route' => null, 'url' => null], ], ], ]; if (!isset($pagesConfig[$currentPage])) { $currentPage = 'articles.index'; } $activeConfig = $pagesConfig[$currentPage]; $breadcrumbBladeCode = file_get_contents(__DIR__ . '/../resources/views/partials/breadcrumb.blade.php'); ?> Bài 09: Tối ưu hóa Named Routes & Breadcrumb động - Lab 07
Thực nghiệm Breadcrumb động theo từng Named Route
$cfg): ?>
Thanh Breadcrumb hiển thị trên giao diện (`@include('partials.breadcrumb')`):
Bảng đối chiếu URL cứng vs. Named Routes tối ưu:
Cách viết URL cứng (Không khuyến khích) Cách tối ưu bằng Named Route (Chuẩn) URL sinh ra
url('/articles') route('articles.index') /articles
url('/articles/create') route('articles.create') /articles/create
url('/articles/' . $article->id) route('articles.show', $article) /articles/1
url('/articles/' . $article->id . '/edit') route('articles.edit', $article) /articles/1/edit
url('/articles/slug/' . $article->slug) route('articles.show.slug', $article->slug) /articles/slug/lam-chu-laravel
Mã nguồn `resources/views/partials/breadcrumb.blade.php`: