2021-07-16 02:35:54 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
|
|
|
|
class User extends Authenticatable
|
|
|
|
{
|
|
|
|
use HasFactory, Notifiable;
|
|
|
|
|
2021-08-11 00:55:34 -04:00
|
|
|
protected $appends = ['tips_count', 'tips_total', 'memes_count'];
|
2021-07-16 02:35:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $fillable = [
|
|
|
|
'name',
|
|
|
|
'email',
|
|
|
|
'address',
|
|
|
|
'password',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that should be hidden for arrays.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $hidden = [
|
|
|
|
'password',
|
|
|
|
'remember_token',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that should be cast to native types.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
|
|
|
'email_verified_at' => 'datetime',
|
|
|
|
];
|
|
|
|
|
|
|
|
public function memes()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Meme::class)->orderByDesc('created_at');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tips()
|
|
|
|
{
|
2021-08-06 16:06:07 -04:00
|
|
|
return $this->hasManyThrough(Tip::class, Meme::class, 'user_id');
|
2021-07-16 02:35:54 -04:00
|
|
|
}
|
|
|
|
|
2021-08-11 00:55:34 -04:00
|
|
|
public function getMemesCountAttribute()
|
2021-07-16 02:35:54 -04:00
|
|
|
{
|
|
|
|
return $this->memes->count();
|
|
|
|
}
|
|
|
|
|
2021-08-11 00:55:34 -04:00
|
|
|
public function getTipsCountAttribute()
|
|
|
|
{
|
|
|
|
return $this->tips->where('is_deposit', 1)->count();
|
|
|
|
}
|
|
|
|
|
2021-07-16 02:35:54 -04:00
|
|
|
public function getTipsTotalAttribute()
|
|
|
|
{
|
2021-07-26 22:39:11 -04:00
|
|
|
return $this->tips->where('is_deposit', 1)->sum('amount_formatted');
|
2021-07-16 02:35:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|