changes 0328092025
This commit is contained in:
+21
-7
@@ -6,11 +6,13 @@
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class Activity extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\ActivityFactory> */
|
||||
use HasFactory;
|
||||
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
@@ -20,7 +22,8 @@ class Activity extends Model
|
||||
'action_id',
|
||||
'user_id',
|
||||
'decision_id',
|
||||
'contract_id'
|
||||
'contract_id',
|
||||
'client_case_id',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
@@ -28,19 +31,25 @@ class Activity extends Model
|
||||
'decision_id',
|
||||
'client_case_id',
|
||||
'user_id',
|
||||
'contract_id'
|
||||
'contract_id',
|
||||
];
|
||||
|
||||
protected static function booted(){
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function (Activity $activity) {
|
||||
if(!isset($activity->user_id)){
|
||||
if (! isset($activity->user_id)) {
|
||||
$activity->user_id = auth()->id();
|
||||
}
|
||||
|
||||
// If an activity with a due date is added for a contract, update the related account's promise_date
|
||||
if (! empty($activity->contract_id) && ! empty($activity->due_date)) {
|
||||
DB::table('accounts')
|
||||
->where('contract_id', $activity->contract_id)
|
||||
->update(['promise_date' => $activity->due_date, 'updated_at' => now()]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function action(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Action::class);
|
||||
@@ -56,8 +65,13 @@ public function clientCase(): BelongsTo
|
||||
return $this->belongsTo(\App\Models\ClientCase::class);
|
||||
}
|
||||
|
||||
public function contract(): BelongsTo|null
|
||||
public function contract(): ?BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Contract::class);
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\User::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user