mirror of
https://github.com/flarum/core.git
synced 2025-10-12 23:44:27 +02:00
Refactor ListPostsController, make filtering extensible
It became apparent in https://github.com/flarum/core/issues/319#issuecomment-170558573 that there was no way for extensions to add filter parameters to the /api/posts endpoint (e.g. /api/posts?filter[mentioned]=1). Simply adding an event to modify the `$where` array severely limits how much can be done with the query. This commit refactors the controller so that filters are applied directly to the query Builder, and exposes the Builder in a new `ConfigurePostsQuery` event.
This commit is contained in:
@@ -18,6 +18,16 @@ use Flarum\Core\Discussion;
|
||||
|
||||
class PostRepository
|
||||
{
|
||||
/**
|
||||
* Get a new query builder for the posts table.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function query()
|
||||
{
|
||||
return Post::query();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a post by ID, optionally making sure it is visible to a certain
|
||||
* user, or throw an exception.
|
||||
|
Reference in New Issue
Block a user