Skip to content

Commit

Permalink
fix eager loading
Browse files Browse the repository at this point in the history
  • Loading branch information
fey committed Mar 13, 2024
1 parent abf4212 commit ce975e1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/ExerciseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function index(): View

public function show(Exercise $exercise): View
{
$exercise->load('chapter', 'users');
$exercise->load('chapter', 'users', 'comments');
/** @var User $authUser */
$authUser = auth()->user() ?? new User();
$userCompletedExercise = $authUser->exerciseMembers()
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public function index(): View

$filter = Request::query('filter', '');
$statisticTable = $this->getStatisticTable($filter);
$logItems = Activity::latest()->has('subject')->has('causer')->with('causer')->limit(10)->get();
$logItems = Activity::latest()->has('subject')->has('causer')->with('causer', 'subject')->limit(10)->get();
$chart = ChartHelper::getChart();
$comments = Comment::latest()->has('user')->with('user')->with('commentable')->limit(10)->get();
$comments = Comment::latest()->has('user')->with('user')->with('commentable', 'user')->limit(10)->get();

return view('home.index', compact(
'logItems',
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Comment extends Model

public string $defaultPresenter = CommentPresenter::class;

protected $with = ['user'];
protected $with = ['user', 'commentable', 'parent'];
protected $fillable = ['content', 'commentable_type', 'commentable_id', 'parent_id'];

public function user(): BelongsTo
Expand Down

0 comments on commit ce975e1

Please sign in to comment.