Add the validation for Item that returns message for requests.
This commit is contained in:
@@ -30,5 +30,26 @@ class Item extends Model
|
||||
{
|
||||
return $this->belongsToMany(Cart::class, 'carts_items', 'item_id', 'cart_id');
|
||||
}
|
||||
|
||||
public static function validate_with_name(string $name)
|
||||
{
|
||||
$name = $name ?? '';
|
||||
|
||||
if($name == '')
|
||||
return [
|
||||
'error' => 'The item name is empty, please, write the name!!!'
|
||||
];
|
||||
|
||||
$item = Item::where('name', $name)->first();
|
||||
|
||||
if(!$item)
|
||||
return [
|
||||
'error' => 'A item with the name does not exist!!!'
|
||||
];
|
||||
|
||||
return [
|
||||
'ok' => 'A item with the name is valid.'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user