Add the validation for City, User that returns message for requests.
This commit is contained in:
@@ -14,4 +14,25 @@ class City extends Model
|
||||
'name',
|
||||
'url',
|
||||
];
|
||||
|
||||
public static function validate_with_name(string $name)
|
||||
{
|
||||
$name = $name ?? '';
|
||||
|
||||
if($name == '')
|
||||
return [
|
||||
'error' => 'The city name is empty, please, write the name!!!'
|
||||
];
|
||||
|
||||
$city = City::where('name', $name)->first();
|
||||
|
||||
if(!$city)
|
||||
return [
|
||||
'error' => 'A city with the name does not exist!!!'
|
||||
];
|
||||
|
||||
return [
|
||||
'ok' => 'A city with the name is valid.'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user