return [
// Özelliği etkinleştir/devre dışı bırak
'enabled' => env('NAMED_ROUTE_BINDING_ENABLED', true),
];
Route::get('/categories/{category}/products/{product}', [ProductController::class, 'show']);
// Her iki yazım da çalışır
public function show($category, $product) { }
public function show($product, $category) { }
Route::get('/users/{user_id}', [UserController::class, 'show']);
// Her ikisi de çalışır
public function show($user_id) { }
public function show($userId) { }
Route::get('/users/{user}', [UserController::class, 'show']);
public function show(Request $request, $user)
{
// $request otomatik enjekte edilir
// $user route parametresinden gelir
}
// Sıra değiştirilebilir
public function show($user, Request $request) { }
Route::get('/posts/{post}', [PostController::class, 'show']);
public function show($post, $format = 'json')
{
// $format varsayılan değeri kullanır
}
public function show($post, ?string $optional)
{
// $optional null olur eğer route'da yoksa
}
Route::get('/users/{user}/posts/{post}', [PostController::class, 'show']);
// Type-hinted modeller otomatik çözümlenir
public function show(Post $post, User $user)
{
// $post ve $user model instance'ları olarak gelir
}
// routes/web.php
Route::get('/shops/{shop}/categories/{category}/products/{product}', [ProductController::class, 'show']);
// ProductController.php - İstediğiniz sırada
public function show(
Request $request,
Product $product, // 3. route parametresi
Category $category, // 2. route parametresi
Shop $shop // 1. route parametresi
) {
// Hepsi doğru şekilde eşleşir!
}
// routes/api.php
Route::get('/teams/{team}/members/{member}/tasks/{task}', [TaskController::class, 'show']);
// TaskController.php
public function show(Task $task, Member $member, Team $team)
{
$this->authorize('view', [$task, $team]);
return new TaskResource($task);
}
// routes/web.php
Route::get('/users/{user}/posts/{post}', [PostController::class, 'show']);
// PostController.php - Parameters must be IN ORDER!
public function show($user, $post)
{
// $user = {user} route parameter
// $post = {post} route parameter
}
// ❌ This DOESN'T WORK! Wrong order means $post gets user value
public function show($post, $user)
{
// $post = {user} route parameter (WRONG!)
// $user = {post} route parameter (WRONG!)
}
// routes/web.php
Route::get('/users/{user}/posts/{post}', [PostController::class, 'show']);
// PostController.php - Order NO LONGER matters!
public function show($post, $user)
{
// ✅ $post = {post} route parameter (MATCHED BY NAME!)
// ✅ $user = {user} route parameter (MATCHED BY NAME!)
}
// Write them in any order you want
public function show($user, $post) // ✅ Works
public function show($post, $user) // ✅ Works
Route::get('/categories/{category}/products/{product}', [ProductController::class, 'show']);
// Both work
public function show($category, $product) { }
public function show($product, $category) { }
Route::get('/users/{user_id}', [UserController::class, 'show']);
// Both work
public function show($user_id) { }
public function show($userId) { }
Route::get('/users/{user}', [UserController::class, 'show']);
public function show(Request $request, $user)
{
// $request is auto-injected
// $user comes from route parameter
}
// Order can be changed
public function show($user, Request $request) { }
Route::get('/posts/{post}', [PostController::class, 'show']);
public function show($post, $format = 'json')
{
// $format uses default value
}
public function show($post, ?string $optional)
{
// $optional is null if not in route
}
Route::get('/users/{user}/posts/{post}', [PostController::class, 'show']);
// Type-hinted models are automatically resolved
public function show(Post $post, User $user)
{
// $post and $user come as model instances
}
// routes/web.php
Route::get('/shops/{shop}/categories/{category}/products/{product}', [ProductController::class, 'show']);
// ProductController.php - Any order you want
public function show(
Request $request,
Product $product, // 3rd route parameter
Category $category, // 2nd route parameter
Shop $shop // 1st route parameter
) {
// All matched correctly!
}
// routes/api.php
Route::get('/teams/{team}/members/{member}/tasks/{task}', [TaskController::class, 'show']);
// TaskController.php
public function show(Task $task, Member $member, Team $team)
{
$this->authorize('view', [$task, $team]);
return new TaskResource($task);
}