-
Notifications
You must be signed in to change notification settings - Fork 0
5. Validation
Ordent Official edited this page Jul 29, 2017
·
3 revisions
In order to enable validation you just need to add this bit of code to your Model class. The function of these two block of code is simple, first Laravel Form Request Validation will check from the model if they have getRules method. It then get the rules needed either for store operation or update operation. Next you should just change the $rules variable with your corresponding rules. If method getRules is not found on the model, Laravel will simply skip the validation checking.
protected $rules = [
"store" => [
"avatar" => "required",
"password" => "required",
"name" => "required",
"email" => "required|unique:users "
],
"update" => []
];
public function getRules($key = null)
{
if ($key != null && array_key_exists($key, $this->rules)) {
return $this->rules[$key];
} else {
return [];
}
}