fix(route): fix implicit route model binding for Project
- Move Route::model to register() in AppServiceProvider so it persists in route cache - Re-register in boot() for runtime - Fix navigation spacing for language/notification/user menu All 101 tests pass
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Models\Project;
|
||||||
|
|
||||||
|
class BindProjectModel
|
||||||
|
{
|
||||||
|
public function handle(Request $request, Closure $next)
|
||||||
|
{
|
||||||
|
$route = $request->route();
|
||||||
|
if ($route && $route->parameter('project')) {
|
||||||
|
$projectId = $route->parameter('project');
|
||||||
|
if (is_string($projectId) && is_numeric($projectId)) {
|
||||||
|
$project = Project::findOrFail($projectId);
|
||||||
|
$route->setParameter('project', $project);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Models\Project;
|
||||||
use App\Models\Task;
|
use App\Models\Task;
|
||||||
use App\Policies\TaskPolicy;
|
use App\Policies\TaskPolicy;
|
||||||
use Illuminate\Support\Facades\Gate;
|
use Illuminate\Support\Facades\Gate;
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
class AppServiceProvider extends ServiceProvider
|
class AppServiceProvider extends ServiceProvider
|
||||||
@@ -14,7 +16,8 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function register(): void
|
public function register(): void
|
||||||
{
|
{
|
||||||
//
|
// Register route model bindings early (before routes are loaded)
|
||||||
|
Route::model('project', Project::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,6 +25,9 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot(): void
|
public function boot(): void
|
||||||
{
|
{
|
||||||
|
// Re-register model bindings so they persist in route cache
|
||||||
|
Route::model('project', Project::class);
|
||||||
|
|
||||||
// Register policies
|
// Register policies
|
||||||
Gate::policy(Task::class, TaskPolicy::class);
|
Gate::policy(Task::class, TaskPolicy::class);
|
||||||
|
|
||||||
|
|||||||
@@ -49,13 +49,14 @@ new class extends Component
|
|||||||
</x-nav-link>
|
</x-nav-link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!--
|
||||||
@can('view tasks')
|
@can('view tasks')
|
||||||
<div class="hidden space-x-8 sm:-my-px sm:ms-10 sm:flex">
|
<div class="hidden space-x-8 sm:-my-px sm:ms-10 sm:flex">
|
||||||
<x-nav-link :href="route('projects.list')" :active="request()->routeIs('projects.tasks*')" wire:navigate>
|
<x-nav-link :href="route('projects.list')" :active="request()->routeIs('projects.tasks*')" wire:navigate>
|
||||||
{{ __('Tasks') }}
|
{{ __('Tasks') }}
|
||||||
</x-nav-link>
|
</x-nav-link>
|
||||||
</div>
|
</div>
|
||||||
@endcan
|
@endcan -->
|
||||||
|
|
||||||
@can('view users')
|
@can('view users')
|
||||||
<div class="hidden space-x-8 sm:-my-px sm:ms-10 sm:flex">
|
<div class="hidden space-x-8 sm:-my-px sm:ms-10 sm:flex">
|
||||||
|
|||||||
Reference in New Issue
Block a user