1
0
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:
Toby Zerner
2016-01-31 17:06:38 +10:30
parent 36ad4a8554
commit 2018e424ec
3 changed files with 112 additions and 29 deletions

View File

@@ -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.