Pass context to AdapterInterface::newQuery()
This commit is contained in:
parent
cda345d3ad
commit
dbd3ceec9c
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
namespace Tobyz\JsonApiServer\Adapter;
|
||||
|
||||
use Tobyz\JsonApiServer\Context;
|
||||
use Tobyz\JsonApiServer\Schema\Attribute;
|
||||
use Tobyz\JsonApiServer\Schema\HasMany;
|
||||
use Tobyz\JsonApiServer\Schema\HasOne;
|
||||
|
|
@ -27,7 +28,7 @@ interface AdapterInterface
|
|||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function newQuery();
|
||||
public function newQuery(Context $context);
|
||||
|
||||
/**
|
||||
* Manipulate the query to only include resources with the given IDs.
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|||
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphOneOrMany;
|
||||
use InvalidArgumentException;
|
||||
use Tobyz\JsonApiServer\Context;
|
||||
use Tobyz\JsonApiServer\Schema\Attribute;
|
||||
use Tobyz\JsonApiServer\Schema\HasMany;
|
||||
use Tobyz\JsonApiServer\Schema\HasOne;
|
||||
|
|
@ -49,7 +50,7 @@ class EloquentAdapter implements AdapterInterface
|
|||
return $this->model->newInstance();
|
||||
}
|
||||
|
||||
public function newQuery()
|
||||
public function newQuery(Context $context)
|
||||
{
|
||||
return $this->model->query();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ trait FindsResources
|
|||
private function findResource(ResourceType $resource, string $id, Context $context)
|
||||
{
|
||||
$adapter = $resource->getAdapter();
|
||||
$query = $adapter->newQuery();
|
||||
$query = $adapter->newQuery($context);
|
||||
|
||||
run_callbacks($resource->getSchema()->getListeners('scope'), [$query, $context]);
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class Index
|
|||
throw new ForbiddenException;
|
||||
}
|
||||
|
||||
$query = $adapter->newQuery();
|
||||
$query = $adapter->newQuery($context);
|
||||
|
||||
run_callbacks($schema->getListeners('listing'), [$query, $context]);
|
||||
run_callbacks($schema->getListeners('scope'), [$query, $context]);
|
||||
|
|
|
|||
Loading…
Reference in New Issue