ldc-tousenselle/app/Models/User.php
2021-06-22 17:15:02 +02:00

84 lines
1.8 KiB
PHP

<?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 implements MustVerifyEmail
{
use HasFactory;
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'firstname',
'lastname',
'birthdate',
'address',
'address2',
'phone',
'city',
'postcode',
'email',
'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 participations()
{
return $this->hasMany(Participation::class);
}
public function hasWon()
{
return $this->hasMany(InstantGagnant::class);
}
public function winInfo()
{
return $this->hasMany(Winner::class);
}
public function unclaimedInstantGagnants()
{
$wonIds = $this->winInfo()->pluck('instant_gagnant_id')->all();
return $this->hasWon()->get()->filter(function (InstantGagnant $instanGagnant) use ($wonIds) {
return !in_array($instanGagnant->id, $wonIds);
});
}
/**
* Send the email verification notification.
*
* @return void
*/
public function sendEmailVerificationNotification()
{
$this->notify(new \App\Core\Auth\VerifyEmail);
}
}