User.php 854 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. protected $guarded = [];
  12. protected $hidden = [
  13. 'password',
  14. 'remember_token',
  15. ];
  16. /**
  17. * The attributes that should be cast to native types.
  18. *
  19. * @var array
  20. */
  21. protected $casts = [
  22. 'email_verified_at' => 'datetime',
  23. ];
  24. public function generateToken()
  25. {
  26. $this->api_token = Str::random(10);
  27. $this->save();
  28. return $this->api_token;
  29. }
  30. public function role()
  31. {
  32. return $this->belongsTo(Role::class);
  33. }
  34. }