From fd4a37c36a4debfb3557a2d1e83eae03d956335c Mon Sep 17 00:00:00 2001 From: KKlochko Date: Sun, 18 Jun 2023 17:37:14 +0300 Subject: [PATCH] Add the validation for Company that returns message for requests. --- app/Models/Company.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/Models/Company.php b/app/Models/Company.php index 101aa67..0fe26f8 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -21,4 +21,25 @@ class Company extends Model { 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.' + ]; + } }