first commit
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class BodyPart extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'slug',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Equipment extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'slug',
|
||||
];
|
||||
|
||||
protected $table = 'equipment';
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Exercise extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'slug',
|
||||
'exercise_db_id',
|
||||
'gif_url',
|
||||
'instructions',
|
||||
];
|
||||
|
||||
// relations
|
||||
public function targetMuscles()
|
||||
{
|
||||
return $this->belongsToMany(Muscle::class, 'exercise_target_muscle');
|
||||
}
|
||||
|
||||
public function secondaryMuscles()
|
||||
{
|
||||
return $this->belongsToMany(Muscle::class, 'exercise_secondary_muscle');
|
||||
}
|
||||
|
||||
public function bodyParts()
|
||||
{
|
||||
return $this->belongsToMany(BodyPart::class, 'body_part_exercise');
|
||||
}
|
||||
|
||||
public function equipments()
|
||||
{
|
||||
return $this->belongsToMany(Equipment::class, 'equipment_exercise');
|
||||
}
|
||||
|
||||
public function workoutExercises()
|
||||
{
|
||||
return $this->hasMany(WorkoutExercise::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Muscle extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'slug',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Workout extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'title',
|
||||
'notes',
|
||||
'estimated_minutes',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'estimated_minutes' => 'integer',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(WorkoutExercise::class)->orderBy('position');
|
||||
}
|
||||
|
||||
public function exercises(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Exercise::class, 'workout_exercises')
|
||||
->withPivot(['id', 'position', 'sets', 'reps', 'weight', 'rest_seconds', 'notes'])
|
||||
->withTimestamps()
|
||||
->orderBy('workout_exercises.position');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class WorkoutExercise extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'workout_id',
|
||||
'exercise_id',
|
||||
'position',
|
||||
'sets',
|
||||
'reps',
|
||||
'weight',
|
||||
'rest_seconds',
|
||||
'notes',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'position' => 'integer',
|
||||
'sets' => 'integer',
|
||||
'reps' => 'integer',
|
||||
'weight' => 'decimal:2',
|
||||
'rest_seconds' => 'integer',
|
||||
];
|
||||
|
||||
public function workout(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Workout::class);
|
||||
}
|
||||
|
||||
public function exercise(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Exercise::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user