*/ use HasFactory, Notifiable, HasPermissions; // Tambahan: Gunakan HasPermissions /** * The attributes that are mass assignable. * * @var list */ protected $fillable = [ 'name', 'email', 'password', 'role', // Kode existing Anda 'role_id', // Tambahan: ID untuk relasi tabel Role 'phone', ]; /** * The attributes that should be hidden for serialization. * * @var list */ protected $hidden = [ 'password', 'remember_token', ]; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', ]; } /** * Tambahan: Relasi ke tabel Roles * Setiap user memiliki satu Role. */ public function role(): BelongsTo { return $this->belongsTo(Role::class); } public function hasAccess($module, $permission) { // Jika admin, berikan akses penuh secara otomatis if ($this->role && $this->role->slug === 'admin') { return true; } // Cek di tabel role_permissions melalui relasi role return $this->role->permissions() ->where('module_slug', $module) ->where($permission, 1) // $permission berisi 'can_read', 'can_update', dll ->exists(); } }