Fix: Добавлен метод courses() в Organization model

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
mirivlad 2026-03-26 08:51:27 +08:00
parent 2271abf732
commit 32fed5d4b6
3 changed files with 7 additions and 3 deletions

View File

@ -18,7 +18,7 @@ class OrganizationController extends Controller
{
Gate::authorize('viewAny', Organization::class);
$organizations = Organization::withCount('users', 'groups', 'courses')
$organizations = Organization::withCount(['users', 'groups'])
->orderBy('created_at', 'desc')
->paginate(20);

View File

@ -46,6 +46,12 @@ class Organization extends Model
return $this->hasMany(CourseAssignment::class);
}
public function courses()
{
// Получаем курсы через назначения
return $this->hasManyThrough(Course::class, CourseAssignment::class, 'organization_id');
}
public function activeUsers(): HasMany
{
return $this->hasMany(User::class)->where('is_active', true);

View File

@ -74,7 +74,6 @@
<th>Email</th>
<th>Пользователей</th>
<th>Групп</th>
<th>Курсов</th>
<th>Статус</th>
<th>Действия</th>
</tr>
@ -99,7 +98,6 @@
<td>{{ $org->email ?? '—' }}</td>
<td>{{ $org->users_count }}</td>
<td>{{ $org->groups_count }}</td>
<td>{{ $org->courses_count ?? 0 }}</td>
<td>
@if($org->is_active)
<span class="badge bg-success">Активна</span>