2025-10-02 22:52:13 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
|
|
|
|
|
|
class User extends Authenticatable
|
|
|
|
|
{
|
|
|
|
|
/** @use HasFactory<\Database\Factories\UserFactory> */
|
|
|
|
|
use HasFactory, Notifiable;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
|
*
|
|
|
|
|
* @var list<string>
|
|
|
|
|
*/
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'name',
|
|
|
|
|
'email',
|
|
|
|
|
'password',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The attributes that should be hidden for serialization.
|
|
|
|
|
*
|
|
|
|
|
* @var list<string>
|
|
|
|
|
*/
|
|
|
|
|
protected $hidden = [
|
|
|
|
|
'password',
|
|
|
|
|
'remember_token',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the attributes that should be cast.
|
|
|
|
|
*
|
|
|
|
|
* @return array<string, string>
|
|
|
|
|
*/
|
|
|
|
|
protected function casts(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'email_verified_at' => 'datetime',
|
|
|
|
|
'password' => 'hashed',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Relationships
|
|
|
|
|
public function workouts()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Workout::class);
|
|
|
|
|
}
|
2025-10-02 23:52:07 +03:00
|
|
|
|
|
|
|
|
public function favoriteExercises()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Exercise::class, 'exercise_favorites')->withTimestamps();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function favoriteWorkouts()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Workout::class, 'workout_favorites')->withTimestamps();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Helpers
|
|
|
|
|
public function hasFavoritedExercise(Exercise $exercise): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->favoriteExercises()->where('exercise_id', $exercise->id)->exists();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function hasFavoritedWorkout(Workout $workout): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->favoriteWorkouts()->where('workout_id', $workout->id)->exists();
|
|
|
|
|
}
|
2025-10-02 22:52:13 +03:00
|
|
|
}
|