Lots of changes

This commit is contained in:
Simon Pocrnjič
2024-11-13 22:11:07 +01:00
parent 90a5858320
commit 953ff38d64
76 changed files with 2822 additions and 427 deletions
+16 -9
View File
@@ -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);
}
}
+6
View File
@@ -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);