Add the validation for Company that returns message for requests.

main
KKlochko 2 years ago
parent 76f6c699aa
commit fd4a37c36a

@ -21,4 +21,25 @@ class Company extends Model
{ {
return $this->hasMany(Category::class); return $this->hasMany(Category::class);
} }
public static function validate_with_name(string $name)
{
$name = $name ?? '';
if($name == '')
return [
'error' => 'The company name is empty, please, write the name!!!'
];
$company = company::where('name', $name)->first();
if(!$company)
return [
'error' => 'A company with the name does not exist!!!'
];
return [
'ok' => 'A company with the name is valid.'
];
}
} }

Loading…
Cancel
Save