Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| User | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 1 |
| booted | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Models; |
| 4 | |
| 5 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
| 6 | use Illuminate\Foundation\Auth\User as Authenticatable; |
| 7 | use Illuminate\Notifications\Notifiable; |
| 8 | use Illuminate\Support\Facades\Hash; |
| 9 | use Illuminate\Support\Str; |
| 10 | |
| 11 | /** |
| 12 | * @property integer $id Id. |
| 13 | * @property string $lastname Nom. |
| 14 | * @property string $firstname Prénom. |
| 15 | * @property string $email Email. |
| 16 | * @property string $password Mot de passe. |
| 17 | * @property string|null $remember_token Token mot de passe. |
| 18 | * @property-read \Illuminate\Support\Carbon $created_at Created date. |
| 19 | * @property-read \Illuminate\Support\Carbon $updated_at Updated date. |
| 20 | */ |
| 21 | class User extends Authenticatable |
| 22 | { |
| 23 | use HasFactory; |
| 24 | use Notifiable; |
| 25 | |
| 26 | /** |
| 27 | * The attributes that are mass assignable. |
| 28 | * |
| 29 | * @var array |
| 30 | */ |
| 31 | protected $fillable = [ |
| 32 | 'lastname', |
| 33 | 'firstname', |
| 34 | 'email', |
| 35 | 'password', |
| 36 | ]; |
| 37 | |
| 38 | /** |
| 39 | * The attributes that should be hidden for arrays. |
| 40 | * |
| 41 | * @var array |
| 42 | */ |
| 43 | protected $hidden = [ |
| 44 | 'password', |
| 45 | 'remember_token', |
| 46 | ]; |
| 47 | |
| 48 | /** |
| 49 | * Perform any actions required after the model boots. |
| 50 | * |
| 51 | * @return void |
| 52 | */ |
| 53 | protected static function booted(): void |
| 54 | { |
| 55 | // * EVENT CLOSURES. |
| 56 | static::creating(function (self $model) { |
| 57 | if (Hash::needsRehash($model->password)) { |
| 58 | $model->password = Hash::make($model->password); |
| 59 | } |
| 60 | $model->remember_token = Str::random(10); |
| 61 | }); |
| 62 | static::updating(function (self $model) { |
| 63 | if (Hash::needsRehash($model->password)) { |
| 64 | $model->password = Hash::make($model->password); |
| 65 | } |
| 66 | $model->remember_token = Str::random(10); |
| 67 | }); |
| 68 | } |
| 69 | } |