Initial refactoring work
This commit is contained in:
62
app/User.php
62
app/User.php
@@ -7,6 +7,9 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
protected $table = 'ab_account';
|
||||
private $_currency;
|
||||
|
||||
use Notifiable;
|
||||
|
||||
/**
|
||||
@@ -32,7 +35,33 @@ class User extends Authenticatable
|
||||
*/
|
||||
public function country()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Country');
|
||||
return $this->belongsTo(Models\Country::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* This users invoices
|
||||
*/
|
||||
public function invoices()
|
||||
{
|
||||
return $this->hasMany(Models\Invoice::class,'account_id');
|
||||
}
|
||||
|
||||
public function language()
|
||||
{
|
||||
return $this->belongsTo(Models\Language::class);
|
||||
}
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany(Models\Payment::class,'account_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* This users invoices
|
||||
*/
|
||||
public function services()
|
||||
{
|
||||
return $this->hasMany(Models\Service::class,'account_id');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,8 +75,35 @@ class User extends Authenticatable
|
||||
/**
|
||||
* Return the user's full name
|
||||
*/
|
||||
public function getNameAttribute($value)
|
||||
public function getFullNameAttribute()
|
||||
{
|
||||
return $this->firstname.' '.$this->lastname;
|
||||
return $this->first_name.' '.$this->last_name;
|
||||
}
|
||||
|
||||
public function getInvoicesDueAttribute()
|
||||
{
|
||||
return $this->invoices
|
||||
->where('active',TRUE)
|
||||
->sortBy('id')
|
||||
->transform(function ($item) { if ($item->due) return $item; })
|
||||
->reverse()
|
||||
->filter();
|
||||
}
|
||||
|
||||
public function getPaymentHistoryAttribute()
|
||||
{
|
||||
return $this->payments
|
||||
->sortBy('date_payment')
|
||||
->reverse();
|
||||
}
|
||||
|
||||
public function getNameAttribute()
|
||||
{
|
||||
return $this->full_name;
|
||||
}
|
||||
|
||||
public function getServicesActiveAttribute()
|
||||
{
|
||||
return $this->services->where('active',TRUE);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user