first commit
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user