No app/Notifications existed beyond Laravel's stock email verification and password reset - nothing brought lapsed users back. Adds a queued InactivityReminder mail notification and a scheduled command (app:send-inactivity-reminders, daily at 09:00) that emails verified users with no completed workout session in the last 5 days, at most once per 7-day cooldown so it can't spam. Skips brand-new signups so it doesn't nag someone who registered an hour ago. Verified the full pipeline live: scheduled command queues the notification (QUEUE_CONNECTION=database), a queue worker processes it, and the rendered email lands in the log driver with a working link back to /workouts. Production still needs cron actually invoking `php artisan schedule:run` every minute and a running queue worker - that's part of the pending deployment setup, not something this change can provide on its own. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
134 lines
3.3 KiB
PHP
134 lines
3.3 KiB
PHP
<?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',
|
|
'age',
|
|
'weight_kg',
|
|
'height_cm',
|
|
'fitness_level',
|
|
'goal',
|
|
'health_notes',
|
|
'available_equipment',
|
|
'days_per_week',
|
|
'minutes_per_session',
|
|
'is_trainer',
|
|
];
|
|
|
|
/**
|
|
* 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',
|
|
'age' => 'integer',
|
|
'weight_kg' => 'decimal:2',
|
|
'height_cm' => 'decimal:2',
|
|
'days_per_week' => 'integer',
|
|
'minutes_per_session' => 'integer',
|
|
'is_admin' => 'boolean',
|
|
'is_trainer' => 'boolean',
|
|
];
|
|
}
|
|
|
|
// Relationships
|
|
public function workouts()
|
|
{
|
|
return $this->hasMany(Workout::class);
|
|
}
|
|
|
|
public function programs()
|
|
{
|
|
return $this->hasMany(Program::class);
|
|
}
|
|
|
|
public function workoutSessions()
|
|
{
|
|
return $this->hasMany(WorkoutSession::class);
|
|
}
|
|
|
|
// 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');
|
|
}
|
|
|
|
public function favoriteExercises()
|
|
{
|
|
return $this->belongsToMany(Exercise::class, 'exercise_favorites')->withTimestamps();
|
|
}
|
|
|
|
public function favoriteWorkouts()
|
|
{
|
|
return $this->belongsToMany(Workout::class, 'workout_favorites')->withTimestamps();
|
|
}
|
|
|
|
public function favoriteYogaPoses()
|
|
{
|
|
return $this->belongsToMany(YogaPose::class, 'yoga_pose_favorites')->withTimestamps();
|
|
}
|
|
|
|
public function weightLogs()
|
|
{
|
|
return $this->hasMany(WeightLog::class);
|
|
}
|
|
|
|
// 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();
|
|
}
|
|
|
|
public function hasFavoritedYogaPose(YogaPose $pose): bool
|
|
{
|
|
return $this->favoriteYogaPoses()->where('yoga_pose_id', $pose->id)->exists();
|
|
}
|
|
}
|