Add ItemValidationByName.
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-08-20 11:14:23 +03:00
parent c9974b007a
commit 8c62393d3f
6 changed files with 97 additions and 48 deletions
+10 -17
View File
@@ -7,7 +7,9 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Item extends Model
use App\Models\Validation\ValidationByNameInterface;
class Item extends Model implements ValidationByNameInterface
{
use HasFactory;
@@ -87,25 +89,16 @@ class Item extends Model
return $its_company->id == $company->id;
}
public static function validate_with_name(string $name)
public static function isExistByName(string $name): bool
{
$name = $name ?? '';
$count = Item::where('name', $name)->count();
if($name == '')
return [
'error' => 'The item name is empty, please, write the name!!!'
];
return $count != 0;
}
$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.'
];
public static function isNameValid(string $name): bool
{
return $name != '';
}
}