| Current Path : /home/users/unlimited/www/sigmaerp.codeskitter.site/app/Models/Accounts/ |
| Current File : /home/users/unlimited/www/sigmaerp.codeskitter.site/app/Models/Accounts/Account.php |
<?php
namespace App\Models\Accounts;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Model;
use App\Models\User;
use App\Models\Accounts\AccountGroup;
class Account extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'description',
'group_id',
'expense_category_id',
'party_id',
'payment_type_bank_id',
'is_deletable',
];
/**
* Insert & update User Id's
* */
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->created_by = auth()->id();
$model->updated_by = auth()->id();
});
static::updating(function ($model) {
$model->updated_by = auth()->id();
});
}
/**
* Define the relationship between Order and User.
*
* @return BelongsTo
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by');
}
/**
* Self Account Group name access
*
* @return BelongsTo
*/
public function group(): BelongsTo
{
return $this->belongsTo(AccountGroup::class, 'group_id'); // 'parent_id' is the foreign key
}
}