osb/app/User.php

110 lines
2.0 KiB
PHP

<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
protected $table = 'ab_account';
private $_currency;
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* Return the country the user belongs to
*/
public function 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');
}
/**
* Only query active categories
*/
public function scopeActive()
{
return $this->where('active',TRUE);
}
/**
* Return the user's full name
*/
public function getFullNameAttribute()
{
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);
}
}