Skip to content

Validate certain fields PATCH #25

Open
@ghost

Description

Hi,

I am trying to modify an entity by using the PATCH method. The entity has 3 fields: 'firstname', 'lastname' and 'address', so I am sending only one of those parameters to the update method of the repository. However it is validating all of them.

This is my validator

class UserValidator extends LaravelValidator
{
    protected $rules = [
        ValidatorInterface::RULE_CREATE => [
            'firstname' => 'required',
            'lastname' => 'required',
            'address' => 'required'
        ],
        ValidatorInterface::RULE_UPDATE => [
            'firstname' => 'required',
            'lastname' => 'required',
            'address' => 'required'
        ],
   ];  
}

This is my controller:

public function update(Request $request, $id)
{
       $this->repository->update($request->all(), $id);
        return $this->response->created();
}  

The $request->all is a single field. Additionally this is my repository:

use Prettus\Repository\Eloquent\BaseRepository;
class UserRepositoryEloquent extends BaseRepository
{
    # do nothing because it extends the update of the BaseRpository
}

However by sending a single field to update, the others fields are being validated and as a consequence I receive an validation error. The only field that should be validated is the one send in the attributes array. I would like to know how could I use the PATCH then?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions