2020-04-12 00:26:44 +02:00
|
|
|
<?php
|
|
|
|
|
2020-06-02 23:45:25 +02:00
|
|
|
namespace App\Member;
|
2020-04-12 00:26:44 +02:00
|
|
|
|
|
|
|
use App\Events\MemberCreated;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
|
|
|
|
class Member extends Model
|
|
|
|
{
|
|
|
|
use Notifiable;
|
|
|
|
|
2021-04-10 03:08:34 +02:00
|
|
|
public $fillable = ['firstname', 'lastname', 'nickname', 'other_country', 'birthday', 'joined_at', 'send_newspaper', 'address', 'further_address', 'zip', 'location', 'main_phone', 'mobile_phone', 'work_phone', 'fax', 'email', 'email_parents', 'nami_id', 'letter_address', 'country_id', 'way_id', 'nationality_id', 'fee_id', 'region_id', 'gender_id', 'confession_id'];
|
2020-04-12 00:26:44 +02:00
|
|
|
|
|
|
|
public $dates = ['joined_at', 'birthday'];
|
|
|
|
|
|
|
|
public $casts = [
|
2021-04-10 02:11:13 +02:00
|
|
|
'send_newspaper' => 'boolean',
|
2020-04-12 00:26:44 +02:00
|
|
|
'gender_id' => 'integer',
|
|
|
|
'way_id' => 'integer',
|
|
|
|
'country_id' => 'integer',
|
|
|
|
'region_id' => 'integer',
|
|
|
|
'confession_id' => 'integer',
|
|
|
|
'nami_id' => 'integer',
|
|
|
|
];
|
|
|
|
|
2020-06-02 23:45:25 +02:00
|
|
|
public function scopeSearch($q, $text) {
|
|
|
|
return $q->where('firstname', 'LIKE', '%'.$text.'%')
|
|
|
|
->orWhere('lastname', 'LIKE', '%'.$text.'%')
|
|
|
|
->orWhere('address', 'LIKE', '%'.$text.'%')
|
|
|
|
->orWhere('zip', 'LIKE', '%'.$text.'%')
|
2021-04-10 01:39:39 +02:00
|
|
|
->orWhere('location', 'LIKE', '%'.$text.'%');
|
2020-04-12 00:26:44 +02:00
|
|
|
}
|
|
|
|
|
2020-06-02 23:45:25 +02:00
|
|
|
|
2020-04-12 00:26:44 +02:00
|
|
|
//----------------------------------- Getters -----------------------------------
|
|
|
|
public function getFullnameAttribute() {
|
|
|
|
return $this->firstname.' '.$this->lastname;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------- 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()
|
|
|
|
{
|
2020-06-02 23:45:25 +02:00
|
|
|
return $this->belongsTo(App\Way::class);
|
2020-04-12 00:26:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function nationality()
|
|
|
|
{
|
2020-06-02 23:45:25 +02:00
|
|
|
return $this->belongsTo(App\Nationality::class);
|
2020-04-12 00:26:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function memberships()
|
|
|
|
{
|
2020-06-02 23:45:25 +02:00
|
|
|
return $this->hasMany(App\Membership::class);
|
2020-04-12 00:26:44 +02:00
|
|
|
}
|
|
|
|
|
2021-04-10 03:08:34 +02:00
|
|
|
public function fee()
|
2020-04-12 00:26:44 +02:00
|
|
|
{
|
2021-04-10 03:08:34 +02:00
|
|
|
return $this->belongsTo(App\Fee::class);
|
2020-04-12 00:26:44 +02:00
|
|
|
}
|
|
|
|
}
|