'boolean', 'gender_id' => 'integer', 'way_id' => 'integer', 'country_id' => 'integer', 'region_id' => 'integer', 'confession_id' => 'integer', 'nami_id' => 'integer', ]; public function scopeSearch($q, $text) { return $q->where('firstname', 'LIKE', '%'.$text.'%') ->orWhere('lastname', 'LIKE', '%'.$text.'%') ->orWhere('address', 'LIKE', '%'.$text.'%') ->orWhere('zip', 'LIKE', '%'.$text.'%') ->orWhere('location', 'LIKE', '%'.$text.'%'); } //----------------------------------- Getters ----------------------------------- public function getFullnameAttribute() { return $this->firstname.' '.$this->lastname; } public function getHasNamiAttribute() { return $this->nami_id !== null; } //---------------------------------- Relations ---------------------------------- public function country() { return $this->belongsTo(\App\Country::class); } public function gender() { return $this->belongsTo(\App\Gender::class); } public function region() { return $this->belongsTo(\App\Region::class); } public function confession() { return $this->belongsTo(\App\Confession::class); } public function payments() { return $this->hasMany(\App\Payment::class)->orderBy('nr'); } public function way() { return $this->belongsTo(App\Way::class); } public function nationality() { return $this->belongsTo(Nationality::class); } public function memberships() { return $this->hasMany(App\Membership::class); } public function fee() { return $this->belongsTo(Fee::class); } public function billKind() { return $this->belongsTo(BillKind::class); } public function group() { return $this->belongsTo(Group::class); } public static function booted() { static::updating(function($model) { if ($model->nami_id === null) { $model->bill_kind_id = null; } }); static::updated(function($model) { UpdateJob::dispatch($model, auth()->user()); }); } }