Удалить Course.php
This commit is contained in:
parent
eb93322ce7
commit
22ea2ccc8f
42
Course.php
42
Course.php
@ -1,42 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class Course extends Model
|
|
||||||
{
|
|
||||||
use HasFactory;
|
|
||||||
|
|
||||||
protected $fillable = ['title', 'description'];
|
|
||||||
|
|
||||||
public function exercises()
|
|
||||||
{
|
|
||||||
return $this->belongsToMany(Exercise::class, 'course_exercise');
|
|
||||||
}
|
|
||||||
public function patients()
|
|
||||||
{
|
|
||||||
return $this->belongsToMany(User::class, 'course_patient'); // Связь с пациентами через промежуточную таблицу
|
|
||||||
}
|
|
||||||
public function users()
|
|
||||||
{
|
|
||||||
return $this->belongsToMany(User::class)->withTimestamps();
|
|
||||||
}
|
|
||||||
public function isCompleted($userId)
|
|
||||||
{
|
|
||||||
// Получаем все упражнения, связанные с курсом
|
|
||||||
$exercises = $this->exercises;
|
|
||||||
|
|
||||||
// Проверяем, завершены ли все упражнения для данного пользователя
|
|
||||||
foreach ($exercises as $exercise) {
|
|
||||||
// Проверка завершенности упражнения для пользователя через связь с таблицей pivot
|
|
||||||
$completed = $exercise->users()->wherePivot('user_id', $userId)->wherePivot('completed', true)->exists();
|
|
||||||
|
|
||||||
if (!$completed) {
|
|
||||||
return false; // Если хотя бы одно упражнение не завершено
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true; // Все упражнения завершены
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user