composer require sudomabider/laravel-xeditable
That's it.
-
Have your x-editable based requests extend
Sudomabider\LaravelXEditable\XEditableRequest
. This class will first validate the initial request to make sure it's a valid x-editable request, and then rearrange the request parameters into a normal form request, e.g. from{name: 'gender', value: 'male'}
into{gender: 'male'}
-
You may restrict the names allowed from a request
protected function allowedEditableNames() { return ['name', 'gender', 'email']; }
This is particularly useful when multiple x-editable requests are grouped into a single class.
-
Define validation rules as you would in a normal form request:
public function rules() { return [ 'email' => 'required|email' ]; }
You may want to return different rules depending on which parameter is present:
public function rules() { if ($this->exists('email')) { return [ 'email' => 'required|email' ]; } if ($this->exists('name')) { return [ 'name' => 'required|min:3' ]; } }