adrema/app/User/Actions/UpdateAction.php

31 lines
732 B
PHP

<?php
namespace App\User\Actions;
use App\User;
use Illuminate\Validation\Rule;
use Illuminate\Http\JsonResponse;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class UpdateAction
{
use AsAction;
public function rules(): array
{
return [
'firstname' => 'required|string|max:255',
'lastname' => 'required|string|max:255',
'email' => ['required', 'string', 'email', 'max:255', Rule::unique('users', 'email')->ignore(request()->route('user')->id)],
];
}
public function handle(User $user, ActionRequest $request): JsonResponse
{
$user->update($request->validated());
return response()->json([]);
}
}