belongsToMany(City::class, 'cities_companies', 'company_id', 'city_id'); } public function categories(): HasMany { return $this->hasMany(Category::class); } public static function isExist(int $company_id): bool { $count = Company::where('id', $company_id)->count(); return $count != 0; } public static function validateWithName(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.' ]; } }