mirror of
https://github.com/flarum/framework.git
synced 2025-02-21 03:59:39 +08: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:
parent
b481e41a9b
commit
d5149b7406
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user