Skip to content

Instantly share code, notes, and snippets.

@dmsysop
Created April 23, 2020 13:24
Show Gist options
  • Save dmsysop/f43520234e6760a83b893ab474632a84 to your computer and use it in GitHub Desktop.
Save dmsysop/f43520234e6760a83b893ab474632a84 to your computer and use it in GitHub Desktop.
public function rules()
{
switch ($this->method()) {
case 'POST':
$rules = [
'name' => ['required'],
'email' => ['required', 'email', 'min:4', 'max:100', Rule::unique('admins')],
'password' => ['required', 'string', 'min:6', 'max:100'],
'password_confirmation' => ['required', 'string', 'min:6', 'max:100', 'same:password'],
'image' => ['image'],
];
break;
case 'PUT':
case 'PATCH':
$rules = [
'name' => ['required', Rule::unique('admins')->ignore($this->administrator)],
'email' => ['required', 'email', 'min:6', 'max:100', Rule::unique('admins')->ignore($this->administrator)],
'password' => ['string', 'min:6', 'max:100'],
'password_confirmation' => ['string', 'min:6', 'max:100', 'same:password'],
'image' => ['image'],
];
break;
default:
return [];
break;
}
if (request()->file('file') || request()->file('image')) {
$rules = array_merge(
$rules,
['image' => 'image|mimes:jpeg,jpg,png,gif']
);
}
return $rules;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment