changes 0328092025
This commit is contained in:
+16
-12
@@ -3,24 +3,22 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\Uuid;
|
||||
use Illuminate\Database\Eloquent\Factories\BelongsToManyRelationship;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOneOrManyThrough;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Contract extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\ContractFactory> */
|
||||
use HasFactory;
|
||||
use Uuid;
|
||||
|
||||
use SoftDeletes;
|
||||
use Uuid;
|
||||
|
||||
protected $fillable = [
|
||||
'reference',
|
||||
@@ -28,13 +26,13 @@ class Contract extends Model
|
||||
'end_date',
|
||||
'client_case_id',
|
||||
'type_id',
|
||||
'description'
|
||||
'description',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'id',
|
||||
'client_case_id',
|
||||
'type_id'
|
||||
'type_id',
|
||||
];
|
||||
|
||||
public function type(): BelongsTo
|
||||
@@ -47,8 +45,9 @@ public function clientCase(): BelongsTo
|
||||
return $this->belongsTo(\App\Models\ClientCase::class)
|
||||
->with(['person']);
|
||||
}
|
||||
|
||||
public function segments(): BelongsToMany {
|
||||
|
||||
public function segments(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\Segment::class)
|
||||
->withPivot('active', 'created_at')
|
||||
->wherePivot('active', true);
|
||||
@@ -65,6 +64,11 @@ public function objects(): HasMany
|
||||
return $this->hasMany(\App\Models\CaseObject::class, 'contract_id');
|
||||
}
|
||||
|
||||
public function documents(): MorphMany
|
||||
{
|
||||
return $this->morphMany(\App\Models\Document::class, 'documentable');
|
||||
}
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::created(function (Contract $contract): void {
|
||||
@@ -96,7 +100,7 @@ protected static function booted(): void
|
||||
->where('client_case_id', $contract->client_case_id)
|
||||
->where('segment_id', $cfg->segment_id)
|
||||
->first();
|
||||
if (!$attached) {
|
||||
if (! $attached) {
|
||||
\DB::table('client_case_segment')->insert([
|
||||
'client_case_id' => $contract->client_case_id,
|
||||
'segment_id' => $cfg->segment_id,
|
||||
@@ -104,7 +108,7 @@ protected static function booted(): void
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
} elseif (!$attached->active) {
|
||||
} elseif (! $attached->active) {
|
||||
\DB::table('client_case_segment')
|
||||
->where('id', $attached->id)
|
||||
->update(['active' => true, 'updated_at' => now()]);
|
||||
|
||||
Reference in New Issue
Block a user