WIP: User table populated and login

This commit is contained in:
Deon George
2018-07-13 14:53:44 +10:00
parent 96673a9e53
commit 64b6c09b8f
22 changed files with 230 additions and 2692 deletions

View File

@@ -4,13 +4,14 @@ namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\Cache;
use Laravel\Passport\HasApiTokens;
use Leenooks\Carbon;
use App\Models\Account;
use Leenooks\Traits\UserSwitch;
class User extends Authenticatable
{
use Notifiable;
use HasApiTokens,Notifiable,UserSwitch;
protected $dates = ['created_at','updated_at','last_access'];
@@ -32,12 +33,43 @@ class User extends Authenticatable
'password', 'remember_token',
];
public function accounts()
{
return $this->hasMany(Models\Account::class);
}
protected function agents() {
return $this->hasMany(static::class,'parent_id','id');
}
protected function clients() {
return $this->hasMany(\App\User::class);
}
public function invoices()
{
return $this->hasManyThrough(Models\Invoice::class,Models\Account::class);
}
public function payments()
{
return $this->hasManyThrough(Models\Payment::class,Models\Account::class);
}
public function services()
{
return $this->hasManyThrough(Models\Service::class,Models\Account::class);
}
protected function supplier()
{
return $this->belongsTo(static::class,'parent_id','id');
}
protected function suppliers() {
return $this->hasMany(static::class,'parent_id','id');
}
/**
* Logged in users full name
*
@@ -52,7 +84,7 @@ class User extends Authenticatable
* Return a Carbon Date if it has a value.
*
* @param $value
* @return Leenooks\Carbon
* @return \Leenooks\Carbon
* @todo This attribute is not in the schema
*/
public function getLastAccessAttribute($value)
@@ -60,6 +92,28 @@ class User extends Authenticatable
if (! is_null($value))
return new Carbon($value);
}
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 getServicesActiveAttribute()
{
return $this->services
->where('active',TRUE);
}
/**
* @deprecated Use static::getFullNameAttribute()
@@ -70,23 +124,6 @@ class User extends Authenticatable
return $this->full_name;
}
protected function agents() {
return $this->hasMany(static::class,'parent_id','id');
}
protected function clients() {
return $this->hasMany(\App\User::class);
}
protected function supplier()
{
return $this->belongsTo(static::class,'parent_id','id');
}
protected function suppliers() {
return $this->hasMany(static::class,'parent_id','id');
}
// List all the agents, including agents of agents
public function all_agents()
{