mercredi 18 mai 2022

How to check the being unique of the model without sending the model to the update method in laravel?

this is method in UserRepository file:

public function update($request, $id)
{
    $new_request = (object)$request;
    $data = $new_request->all();
    $this->user::where('id', $id)->update($data);
    return http_response_code(201);
}

this is method in UserController:

public function update(UpdateUserRequest $request, $id)
{
    return $this->userRepository->update($request, $id);
}

this is UpdateUserRequest:

'username' => 'required|string',Rule::unique('users')->ignore($this->user),

but don't work and my error is: Attempt to read property "id" on string

Aucun commentaire:

Enregistrer un commentaire