|
3 | 3 | namespace App\Models; |
4 | 4 |
|
5 | 5 | // use Illuminate\Contracts\Auth\MustVerifyEmail; |
| 6 | + |
| 7 | +use Illuminate\Database\Eloquent\Casts\Attribute; |
6 | 8 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
7 | 9 | use Illuminate\Foundation\Auth\User as Authenticatable; |
8 | 10 | use Illuminate\Notifications\Notifiable; |
| 11 | +use Illuminate\Support\Facades\Hash; |
9 | 12 | use Laravel\Sanctum\HasApiTokens; |
10 | 13 |
|
11 | 14 | class User extends Authenticatable |
12 | 15 | { |
13 | | - use HasApiTokens, HasFactory, Notifiable; |
| 16 | + use HasApiTokens; |
| 17 | + use HasFactory; |
| 18 | + use Notifiable; |
14 | 19 |
|
15 | | - /** |
16 | | - * The attributes that are mass assignable. |
17 | | - * |
18 | | - * @var array<int, string> |
19 | | - */ |
20 | 20 | protected $fillable = [ |
21 | 21 | 'name', |
22 | 22 | 'email', |
23 | 23 | 'password', |
24 | 24 | ]; |
25 | 25 |
|
26 | | - /** |
27 | | - * The attributes that should be hidden for serialization. |
28 | | - * |
29 | | - * @var array<int, string> |
30 | | - */ |
31 | 26 | protected $hidden = [ |
32 | 27 | 'password', |
33 | 28 | 'remember_token', |
34 | 29 | ]; |
35 | 30 |
|
36 | | - /** |
37 | | - * The attributes that should be cast. |
38 | | - * |
39 | | - * @var array<string, string> |
40 | | - */ |
41 | 31 | protected $casts = [ |
42 | 32 | 'email_verified_at' => 'datetime', |
43 | 33 | ]; |
| 34 | + |
| 35 | + protected function password(): Attribute |
| 36 | + { |
| 37 | + return Attribute::make( |
| 38 | + set: fn ($value) => Hash::make($value), |
| 39 | + ); |
| 40 | + } |
| 41 | + |
| 42 | + public function organisations() |
| 43 | + { |
| 44 | + return $this->hasMany(Organisation::class); |
| 45 | + } |
| 46 | + |
| 47 | + public function currentOrganisation() |
| 48 | + { |
| 49 | + return $this->belongsTo(Organisation::class); |
| 50 | + } |
44 | 51 | } |
0 commit comments