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',
|
2025-10-04 18:52:44 +03:00
|
|
|
'age',
|
|
|
|
|
'weight_kg',
|
|
|
|
|
'height_cm',
|
|
|
|
|
'fitness_level',
|
|
|
|
|
'goal',
|
|
|
|
|
'health_notes',
|
|
|
|
|
'available_equipment',
|
|
|
|
|
'days_per_week',
|
|
|
|
|
'minutes_per_session',
|
2025-10-06 22:35:04 +03:00
|
|
|
'is_trainer',
|
2025-10-02 22:52:13 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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',
|
2025-10-04 18:52:44 +03:00
|
|
|
'age' => 'integer',
|
|
|
|
|
'weight_kg' => 'decimal:2',
|
|
|
|
|
'height_cm' => 'decimal:2',
|
|
|
|
|
'days_per_week' => 'integer',
|
|
|
|
|
'minutes_per_session' => 'integer',
|
2025-10-06 22:35:04 +03:00
|
|
|
'is_admin' => 'boolean',
|
|
|
|
|
'is_trainer' => 'boolean',
|
2025-10-02 22:52:13 +03:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Relationships
|
|
|
|
|
public function workouts()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Workout::class);
|
|
|
|
|
}
|
2025-10-02 23:52:07 +03:00
|
|
|
|
2026-08-10 12:21:47 +03:00
|
|
|
public function programs()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Program::class);
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 12:32:17 +03:00
|
|
|
public function workoutSessions()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(WorkoutSession::class);
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 12:28:23 +03:00
|
|
|
// Trainer/client relationships
|
|
|
|
|
public function clients()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(User::class, 'trainer_clients', 'trainer_id', 'client_id')->withTimestamps();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function trainers()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(User::class, 'trainer_clients', 'client_id', 'trainer_id')->withTimestamps();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function assignedWorkouts()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Workout::class, 'assigned_by_trainer_id');
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 12:04:50 +03:00
|
|
|
public function favoriteYogaPoses()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(YogaPose::class, 'yoga_pose_favorites')->withTimestamps();
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 12:10:08 +03:00
|
|
|
public function weightLogs()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(WeightLog::class);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-02 23:52:07 +03:00
|
|
|
// 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();
|
|
|
|
|
}
|
2026-08-10 12:04:50 +03:00
|
|
|
|
|
|
|
|
public function hasFavoritedYogaPose(YogaPose $pose): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->favoriteYogaPoses()->where('yoga_pose_id', $pose->id)->exists();
|
|
|
|
|
}
|
2025-10-02 22:52:13 +03:00
|
|
|
}
|