2022-05-31 14:06:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models\Credit;
|
|
|
|
|
|
2023-08-14 09:23:39 +00:00
|
|
|
use App\Enums\Credit\AccountTypeEnum;
|
2022-05-31 14:06:07 +02:00
|
|
|
use App\Models\Brand;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
2023-08-14 09:23:39 +00:00
|
|
|
/**
|
2025-04-08 11:47:49 +02:00
|
|
|
* @property string $label
|
|
|
|
|
* @property \App\Enums\Credit\AccountTypeEnum $type
|
|
|
|
|
* @property integer $balance
|
|
|
|
|
* @property integer $brand_id
|
2023-08-14 09:23:39 +00:00
|
|
|
*/
|
2022-05-31 14:06:07 +02:00
|
|
|
class Account extends Model
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* The table associated with the model.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $table = 'credit_accounts';
|
|
|
|
|
|
|
|
|
|
/**
|
2023-08-14 09:23:39 +00:00
|
|
|
* The attributes that are fillable.
|
2022-05-31 14:06:07 +02:00
|
|
|
*
|
2025-04-08 11:47:49 +02:00
|
|
|
* @var list<string>
|
2022-05-31 14:06:07 +02:00
|
|
|
*/
|
|
|
|
|
protected $fillable = [
|
2023-08-14 09:23:39 +00:00
|
|
|
'label',
|
|
|
|
|
'type',
|
|
|
|
|
'balance',
|
|
|
|
|
'brand_id'
|
2022-05-31 14:06:07 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
2023-08-14 09:23:39 +00:00
|
|
|
* The attributes that should be cast.
|
2022-05-31 14:06:07 +02:00
|
|
|
*
|
2025-04-08 11:47:49 +02:00
|
|
|
* @var array<string, string>
|
2022-05-31 14:06:07 +02:00
|
|
|
*/
|
2023-08-14 09:23:39 +00:00
|
|
|
protected $casts = [
|
|
|
|
|
'type' => AccountTypeEnum::class
|
2022-05-31 14:06:07 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
2023-08-14 09:23:39 +00:00
|
|
|
* Perform any actions required after the model boots.
|
2022-05-31 14:06:07 +02:00
|
|
|
*
|
2023-08-14 09:23:39 +00:00
|
|
|
* @return void
|
2022-05-31 14:06:07 +02:00
|
|
|
*/
|
2025-04-08 11:47:49 +02:00
|
|
|
protected static function booted(): void
|
2022-05-31 14:06:07 +02:00
|
|
|
{
|
2023-08-14 09:23:39 +00:00
|
|
|
static::deleting(function () {
|
|
|
|
|
throw new \Error('Action impossible');
|
|
|
|
|
});
|
2022-05-31 14:06:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// * RELATIONSHIPS
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* BelongsTo Brand relation
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
|
*/
|
2025-04-08 11:47:49 +02:00
|
|
|
public function brand(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2022-05-31 14:06:07 +02:00
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Brand::class);
|
|
|
|
|
}
|
2023-08-14 09:23:39 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* HasOne Account relation
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
|
|
|
|
*/
|
2025-04-08 11:47:49 +02:00
|
|
|
public function creditlogs(): \Illuminate\Database\Eloquent\Relations\HasOne
|
2023-08-14 09:23:39 +00:00
|
|
|
{
|
|
|
|
|
return $this->HasOne(CreditLog::class, 'credit_account_id');
|
|
|
|
|
}
|
2022-05-31 14:06:07 +02:00
|
|
|
}
|