64 خطوط
1.5 KiB
PHP
64 خطوط
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Deal extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'title', 'company_id', 'lead_id', 'contact_id', 'product_id',
|
|
'estimated_value', 'win_probability', 'sales_stage', 'expected_close_date',
|
|
'owner_id', 'status', 'won_lost_reason', 'notes', 'created_by',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'estimated_value' => 'decimal:2',
|
|
'win_probability' => 'integer',
|
|
'expected_close_date' => 'date',
|
|
];
|
|
}
|
|
|
|
public function company(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Company::class);
|
|
}
|
|
|
|
public function lead(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Lead::class);
|
|
}
|
|
|
|
public function contact(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Contact::class);
|
|
}
|
|
|
|
public function product(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Product::class);
|
|
}
|
|
|
|
public function owner(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'owner_id');
|
|
}
|
|
|
|
public function notes(): MorphMany
|
|
{
|
|
return $this->morphMany(Note::class, 'notable');
|
|
}
|
|
|
|
public function attachments(): MorphMany
|
|
{
|
|
return $this->morphMany(Attachment::class, 'attachable');
|
|
}
|
|
}
|