75 خطوط
1.7 KiB
PHP
75 خطوط
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
|
|
class Campaign extends Model
|
|
{
|
|
protected $fillable = [
|
|
'name',
|
|
'description',
|
|
'product_service',
|
|
'product_id',
|
|
'channel',
|
|
'start_date',
|
|
'end_date',
|
|
'target',
|
|
'budget',
|
|
'actual_cost',
|
|
'status',
|
|
'sales_script_id',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'start_date' => 'date',
|
|
'end_date' => 'date',
|
|
'target' => 'integer',
|
|
'budget' => 'decimal:2',
|
|
'actual_cost' => 'decimal:2',
|
|
];
|
|
}
|
|
|
|
public function assignedAgents(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(User::class)
|
|
->wherePivot('role', 'agent')
|
|
->withPivotValue('role', 'agent')
|
|
->withPivot('role');
|
|
}
|
|
|
|
public function assignedSupervisors(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(User::class)
|
|
->wherePivot('role', 'supervisor')
|
|
->withPivotValue('role', 'supervisor')
|
|
->withPivot('role');
|
|
}
|
|
|
|
public function leads(): HasMany
|
|
{
|
|
return $this->hasMany(Lead::class);
|
|
}
|
|
|
|
public function salesScript(): BelongsTo
|
|
{
|
|
return $this->belongsTo(SalesScript::class);
|
|
}
|
|
|
|
public function product(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Product::class);
|
|
}
|
|
|
|
public function tasks(): MorphMany
|
|
{
|
|
return $this->morphMany(Task::class, 'taskable');
|
|
}
|
|
}
|