*/ use HasFactory, Notifiable; /** * The attributes that are mass assignable. * * @var list */ protected $fillable = [ 'name', 'email', 'password', 'google_id', 'role', ]; /** * The attributes that should be hidden for serialization. * * @var list */ protected $hidden = [ 'password', 'remember_token', ]; /** * Send the email verification notification. * * @return void */ public function sendEmailVerificationNotification() { $this->notify(new CustomVerifyEmail); } /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', ]; } /** * Cafe yang difavoritkan oleh user * * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ public function favoriteCafes() { return $this->belongsToMany(Cafe::class, 'favorites', 'user_id', 'cafe_id') ->withTimestamps(); } /** * Cek apakah user sudah memfavoritkan cafe tertentu * * @param int $cafeId * @return bool */ public function hasFavorited($cafeId) { return $this->favorites()->where('cafe_id', $cafeId)->exists(); } public function favorites() { return $this->hasMany(Favorite::class); } }