Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Validate certain fields PATCH #25

Open
ghost opened this issue Oct 4, 2016 · 0 comments
Open

Validate certain fields PATCH #25

ghost opened this issue Oct 4, 2016 · 0 comments

Comments

@ghost
Copy link

ghost commented Oct 4, 2016

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!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants