mirror of
https://github.com/flarum/core.git
synced 2025-07-23 17:51:24 +02:00
Eager load post.user.groups relation and allow extensions to eager load relations (#38)
* Allow extensions to eager load relations * Eager load post.user.groups
This commit is contained in:
@@ -38,16 +38,24 @@ class ListFlagsController extends AbstractListController
|
||||
protected function data(ServerRequestInterface $request, Document $document)
|
||||
{
|
||||
$actor = $request->getAttribute('actor');
|
||||
$include = $this->extractInclude($request);
|
||||
|
||||
$actor->assertRegistered();
|
||||
|
||||
$actor->read_flags_at = time();
|
||||
$actor->save();
|
||||
|
||||
return Flag::whereVisibleTo($actor)
|
||||
->with($this->extractInclude($request))
|
||||
$flags = Flag::whereVisibleTo($actor)
|
||||
->latest('flags.created_at')
|
||||
->groupBy('post_id')
|
||||
->get();
|
||||
|
||||
if (in_array('post.user', $include)) {
|
||||
$include[] = 'post.user.groups';
|
||||
}
|
||||
|
||||
$this->loadRelations($flags, $include);
|
||||
|
||||
return $flags;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user