User.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Contracts\Auth\MustVerifyEmail;
  4. use Illuminate\Database\Eloquent\Factories\HasFactory;
  5. use Illuminate\Foundation\Auth\User as Authenticatable;
  6. use Illuminate\Notifications\Notifiable;
  7. use Illuminate\Support\Str;
  8. class User extends Authenticatable
  9. {
  10. use HasFactory, Notifiable;
  11. /**
  12. * The attributes that are mass assignable.
  13. *
  14. * @var array
  15. */
  16. protected $guarded = [];
  17. /**
  18. * The attributes that should be hidden for arrays.
  19. *
  20. * @var array
  21. */
  22. protected $hidden = [
  23. 'password',
  24. 'remember_token',
  25. ];
  26. /**
  27. * The attributes that should be cast to native types.
  28. *
  29. * @var array
  30. */
  31. protected $casts = [
  32. 'email_verified_at' => 'datetime',
  33. ];
  34. public function generateToken()
  35. {
  36. $this->api_token = Str::random(10);
  37. $this->save();
  38. return $this->api_token;
  39. }
  40. public function role()
  41. {
  42. return $this->belongsTo(Role::class);
  43. }
  44. }