Route::controller(\App\Http\Controllers\OrderController::class)->prefix('/orders')->group(function() {
Route::prefix('/{order}')->group(function() {
Route::patch('/', 'update')->can('view', 'project');
Route::put('/', 'update')->can('view', 'project');
});
});
$this->order->canChangeStatus($this->get('status'))эта проверка не совсем корректна в authorize, так как нам нельзя редактировать именно статус заказа, остальное можно (п. 1 из тела вопроса).
PDOException::("SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value")
# UserSeeder
public function run()
{
foreach (range(1, self::COUNT) as $iteration) {
User::factory()->for(
Project::factory()->count(1)
)->create([
'phone' => 70000000000 + $iteration,
'email' => "test{$iteration}@mail.ru",
]);
}
}
# ProjectFactory
public function definition()
{
return [
'name' => fake()->text(30),
'alias' => fake()->regexify('/^[a-z0-9_\-]+$/'),
];
}
Route::prefix('/projects')->group(function() {
Route::get('/', [ProjectController::class, 'getAll'])->can('getAll', Project::class);
Route::post('/', [ProjectController::class, 'create'])->can('create', Project::class);
Route::prefix('/{project}')->group(function() {
Route::get('/', [ProjectController::class, 'show'])->can('view', 'project');
Route::put('/', [ProjectController::class, 'update'])->can('update', 'project');
Route::patch('/', [ProjectController::class, 'update'])->can('update', 'project');
Route::delete('/', [ProjectController::class, 'destroy'])->can('destroy', 'project');
Route::prefix('/menu')->group(function() {
Route::get('/', [MenuController::class, 'getAll'])->can('view', 'project');
Route::post('/', [MenuController::class, 'create'])->can('isAdmin', 'project');
Route::get('/{menu}', [MenuController::class, 'show'])->scopeBindings();
Route::delete('/{menu}', [MenuController::class, 'destroy']);
});
});
});
public function show(Project $project, Menu $menu)
{
// dd($project->id, $menu->project_id);
$menu = $project->menu()->findOrFail($menu->id);
return $this->baseJson(data: new MenuResource($menu));
}
Спасибо ещё раз огромное.