78 lines
1.5 KiB
PHP
78 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Credit;
|
|
|
|
use App\Enums\Credit\AccountTypeEnum;
|
|
use App\Models\Brand;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* @property string $label
|
|
* @property AccountTypeEnum $type
|
|
* @property integer $balance
|
|
* @property Brand $brand_id
|
|
*/
|
|
class Account extends Model
|
|
{
|
|
/**
|
|
* The table associated with the model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $table = 'credit_accounts';
|
|
|
|
/**
|
|
* The attributes that are fillable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'label',
|
|
'type',
|
|
'balance',
|
|
'brand_id'
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'type' => AccountTypeEnum::class
|
|
];
|
|
|
|
/**
|
|
* Perform any actions required after the model boots.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected static function booted()
|
|
{
|
|
static::deleting(function () {
|
|
throw new \Error('Action impossible');
|
|
});
|
|
}
|
|
|
|
// * RELATIONSHIPS
|
|
|
|
/**
|
|
* BelongsTo Brand relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function brand()
|
|
{
|
|
return $this->belongsTo(Brand::class);
|
|
}
|
|
|
|
/**
|
|
* HasOne Account relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
|
*/
|
|
public function creditlogs()
|
|
{
|
|
return $this->HasOne(CreditLog::class, 'credit_account_id');
|
|
}
|
|
}
|