83 lines
1.7 KiB
PHP
83 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\DeliveryMode\DeliveryModeEnum;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
*
|
|
* @property-read \App\Enums\DeliveryMode\DeliveryModeEnum $mode The delivery mode.
|
|
*
|
|
* @package App\Models
|
|
*/
|
|
class DeliveryMode extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
/**
|
|
* Indicates if the IDs are auto-incrementing.
|
|
*
|
|
* @var boolean
|
|
*/
|
|
public $incrementing = false;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'is_available', 'is_free',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'is_available' => 'bool',
|
|
'is_free' => 'bool',
|
|
];
|
|
|
|
/**
|
|
* Perform any actions required after the model boots.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected static function booted()
|
|
{
|
|
// * EVENT CLOSURES.
|
|
static::creating(function (self $model) {
|
|
throw new \RuntimeException("Creating {$model->id} is not allowed", 1);
|
|
});
|
|
static::deleting(function (self $model) {
|
|
throw new \RuntimeException("Deleting {$model->id} is not allowed", 1);
|
|
});
|
|
}
|
|
|
|
// * METHODS
|
|
|
|
/**
|
|
* Getter mode
|
|
*
|
|
* @return \App\Enums\DeliveryMode\DeliveryModeEnum
|
|
*/
|
|
public function getModeAttribute(): DeliveryModeEnum
|
|
{
|
|
return DeliveryModeEnum::make(\intval($this->id));
|
|
}
|
|
|
|
/**
|
|
* Query available delivery Methods
|
|
*
|
|
* @return Builder
|
|
*/
|
|
public static function availables(): Builder
|
|
{
|
|
return self::whereIsAvailable(true);
|
|
}
|
|
}
|