why loadWhere
callback is never called there
(new Extend\ApiController(ShowForumController::class))
->loadWhere('groups', function ($query, $request) {
echo 'something';
})
why loadWhere
callback is never called there
(new Extend\ApiController(ShowForumController::class))
->loadWhere('groups', function ($query, $request) {
echo 'something';
})
luceos yes. It's just empty extension
.
<?php
namespace My\FlarumExt;
use Flarum\Extend;
use Flarum\Api\Controller\ShowForumController;
return [
(new Extend\ApiController(ShowForumController::class))
->loadWhere('groups', function ($query, $request) {
echo 'something';
dd('something');
throw 1;
})
];
Yes, other things are executed well, the problem occured only with this
Are there way to force eager loads the required relationships even if controller is not calling loadRelations
? ( It's protected function so I can't even manually call it )
I'm on mobile so cannot check further right now, but I believe the extender you are using is specifically for serializers based on Eloquent models. But the forum serializer is not based on a model, and therefore doesn't have Eloquent relationships.
The relations on the forum serializer are all hard-coded data. There's another extender hook for before data serialization that can be used for this.
What are you trying to do though? The groups
relation is not a real relation. If you want to make some groups invisible, you should use a visibility scoper. If you want to pre-load specific groups to render in a dropdown list in your extension UI, you should create a new virtual relationship with a unique name, or load the data asynchronously from an API endpoint when needed.
clarkwinkelmann I'm need to serialize another relationship for actor
-> actor.my_relation
( this part is working ) and actor
itself is loading to frontend in ShowForumController
, also I'm need to eager loads the required relationship.
bradraj the actor is probably serialized using the CurrentUserSerializer, one should probably extend that:
flarum/frameworkblob/1.x/framework/core/src/Api/Serializer/CurrentUserSerializer.php with flarum/frameworkblob/1.x/framework/core/src/Extend/ApiSerializer.php
As there's always a single actor, eager loading would not bring any performance improvement
clarkwinkelmann I'm using eager loader for apply visible scoper to model relationship that includes in show controller