Lots of changes
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class Person extends Model
|
||||
@@ -43,6 +44,14 @@ class Person extends Model
|
||||
'user_id'
|
||||
];
|
||||
|
||||
protected static function booted(){
|
||||
static::creating(function (Person $person) {
|
||||
if(!isset($person->user_id)){
|
||||
$person->user_id = auth()->id();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public function phones(): HasMany
|
||||
{
|
||||
@@ -68,16 +77,14 @@ public function type(): BelongsTo
|
||||
return $this->belongsTo(\App\Models\Person\PersonType::class, 'type_id');
|
||||
}
|
||||
|
||||
public function contracts(): HasMany
|
||||
public function client(): HasOne
|
||||
{
|
||||
return $this->hasMany(\App\Models\Contract::class, 'client_id')
|
||||
->with('debtor', fn($que) =>
|
||||
$que->with(['type', 'group'])
|
||||
->whereHas('type', fn($tque) => $tque->where('deleted','=',0))
|
||||
->whereHas('group', fn($tque) => $tque->where('deleted','=',0))
|
||||
->where('active','=',1))
|
||||
->with('type', fn($que) => $que->where('deleted','=',0))
|
||||
->where('active', '=', 1);
|
||||
return $this->hasOne(\App\Models\Client::class);
|
||||
}
|
||||
|
||||
public function clientCase(): HasOne
|
||||
{
|
||||
return $this->hasOne(\App\Models\ClientCase::class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,12 @@ class PersonAddress extends Model
|
||||
'deleted'
|
||||
];
|
||||
|
||||
protected static function booted(){
|
||||
static::creating(function (PersonAddress $address) {
|
||||
$address->user_id = auth()->id();
|
||||
});
|
||||
}
|
||||
|
||||
public function person(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Person\Person::class);
|
||||
|
||||
Reference in New Issue
Block a user