update addon HRM
Some checks failed
Some checks failed
This commit is contained in:
84
Modules/HrmAddon/App/Models/Employee.php
Normal file
84
Modules/HrmAddon/App/Models/Employee.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\HrmAddon\App\Models;
|
||||
|
||||
use App\Models\Branch;
|
||||
use App\Models\Scopes\BranchScope;
|
||||
use App\Traits\ImageUrlTrait;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Employee extends Model
|
||||
{
|
||||
use HasFactory, ImageUrlTrait;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'business_id',
|
||||
'branch_id',
|
||||
'designation_id',
|
||||
'department_id',
|
||||
'shift_id',
|
||||
'phone',
|
||||
'amount',
|
||||
'email',
|
||||
'gender',
|
||||
'country',
|
||||
'birth_date',
|
||||
'join_date',
|
||||
'image',
|
||||
'status',
|
||||
];
|
||||
|
||||
public function branch(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Branch::class)->withTrashed();
|
||||
}
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model) {
|
||||
$model->branch_id = auth()->user()->branch_id ?? auth()->user()->active_branch_id;
|
||||
});
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::addGlobalScope(new BranchScope);
|
||||
|
||||
if (auth()->check() && auth()->user()->accessToMultiBranch()) {
|
||||
static::addGlobalScope('withBranch', function ($builder) {
|
||||
$builder->with('branch:id,name');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function department()
|
||||
{
|
||||
return $this->belongsTo(Department::class);
|
||||
}
|
||||
|
||||
public function designation()
|
||||
{
|
||||
return $this->belongsTo(Designation::class);
|
||||
}
|
||||
|
||||
public function shift()
|
||||
{
|
||||
return $this->belongsTo(Shift::class);
|
||||
}
|
||||
|
||||
protected $casts = [
|
||||
'business_id' => 'integer',
|
||||
'designation_id' => 'integer',
|
||||
'department_id' => 'integer',
|
||||
'shift_id' => 'integer',
|
||||
'amount' => 'double',
|
||||
];
|
||||
|
||||
protected $imageFields = ['image'];
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user