Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Controllers/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Binaryk\LaravelRestify\Http\Requests\RestifyRequest;
use Binaryk\LaravelRestify\Repositories\Repository;
use Binaryk\LaravelRestify\Services\Search\SearchService;
use Binaryk\LaravelRestify\Traits\PerformsQueries;
use Illuminate\Config\Repository as Config;
use Illuminate\Container\Container;
use Illuminate\Contracts\Auth\Access\Gate;
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/RepositoryShowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RepositoryShowController extends RepositoryController
public function handle(RestifyRequest $request)
{
/**
* @var Repository $repository
* @var Repository
*/
$repository = $request->newRepositoryWith(tap(SearchService::instance()->prepareRelations($request, $request->findModelQuery()), function ($query) use ($request) {
$request->newRepository()->detailQuery($request, $query);
Expand Down
6 changes: 2 additions & 4 deletions src/Http/Requests/InteractWithRepositories.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function repository()
]), 404);
}

if ( ! $repository::authorizedToViewAny($this)) {
if (! $repository::authorizedToViewAny($this)) {
throw new UnauthorizedException(__('Unauthorized to view repository :name.', [
'name' => $repository,
]), 403);
Expand Down Expand Up @@ -106,7 +106,7 @@ public function isResolvedByRestify()

/**
* Get a new instance of the repository being requested.
* As a model it could accept either a model instance, a collection or even paginated collection
* As a model it could accept either a model instance, a collection or even paginated collection.
*
* @param $model
* @return Repository
Expand All @@ -118,7 +118,6 @@ public function newRepositoryWith($model)
return new $repository($model);
}


/**
* Get a new, scopeless query builder for the underlying model.
*
Expand Down Expand Up @@ -153,5 +152,4 @@ public function findModelQuery($repositoryId = null)
$repositoryId ?? $this->repositoryId
);
}

}
8 changes: 2 additions & 6 deletions src/Repositories/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* This class serve as repository collection and repository single model
* This allow you to use all of the Laravel default repositories features (as adding headers in the response, or customizing
* response)
* response).
* @author Eduard Lupacescu <eduard.lupacescu@binarcode.com>
*/
abstract class Repository extends RepositoryCollection implements RestifySearchable
Expand All @@ -29,7 +29,7 @@ abstract class Repository extends RepositoryCollection implements RestifySearcha

/**
* This is named `resource` because of the forwarding properties from DelegatesToResource trait.
* This may be a single model or a illuminate collection, or even a paginator instance
* This may be a single model or a illuminate collection, or even a paginator instance.
*
* @var Model|LengthAwarePaginator
*/
Expand All @@ -54,9 +54,7 @@ public function __construct($model)
public function model()
{
if ($this->isRenderingCollection() || $this->isRenderingPaginated()) {

return $this->modelFromIterator();

}

return $this->resource;
Expand Down Expand Up @@ -101,9 +99,7 @@ public function toArray($request)
$request = Container::getInstance()->make('request');

if ($this->isRenderingCollection()) {

return $this->toArrayForCollection($request);

}

$serialized = [
Expand Down
16 changes: 7 additions & 9 deletions src/Repositories/RepositoryCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
use Illuminate\Pagination\AbstractPaginator;
use Illuminate\Support\Arr;


/**
* @package Binaryk\LaravelRestify\Repositories;
* @author Eduard Lupacescu <eduard.lupacescu@binarcode.com>
*/
class RepositoryCollection extends Resource
{
/**
* When the repository is used as a response for a collection list (index controller)
* When the repository is used as a response for a collection list (index controller).
*
* @param $request
* @return array
Expand Down Expand Up @@ -84,7 +82,7 @@ protected function meta($paginated)

/**
* Check if the repository is used as a response for a list of items or for a single
* model entity
* model entity.
* @return bool
*/
protected function isRenderingRepository()
Expand All @@ -94,7 +92,7 @@ protected function isRenderingRepository()

/**
* Check if the repository is used as a response for a list of items or for a single
* model entity
* model entity.
* @return bool
*/
protected function isRenderingCollection()
Expand All @@ -111,21 +109,21 @@ public function isRenderingPaginated()
}

/**
* If collection or paginator then return model from the first item
* If collection or paginator then return model from the first item.
*
* @return Model
*/
protected function modelFromIterator()
{
/**
* @var ArrayIterator $iterator
* @var ArrayIterator
*/
$iterator = $this->iterator();

/**
* This is the first element from the response collection, now we have the class of the restify
* engine
* @var Model $model
* engine.
* @var Model
*/
$model = $iterator->current();

Expand Down
12 changes: 5 additions & 7 deletions src/Repositories/ResponseResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
namespace Binaryk\LaravelRestify\Repositories;

/**
* @package Binaryk\LaravelRestify\Repositories;
* @author Eduard Lupacescu <eduard.lupacescu@binarcode.com>
*/
trait ResponseResolver
{

/**
* Return the attributes list
* Return the attributes list.
*
* @param $request
* @return array
Expand All @@ -35,7 +33,7 @@ public function resolveDetailsMeta($request)
}

/**
* Return a list with relationship for the current model
* Return a list with relationship for the current model.
*
* @param $request
* @return array
Expand All @@ -46,7 +44,7 @@ public function resolveDetailsRelationships($request)
}

/**
* Triggered after toArray
* Triggered after toArray.
*
* @param $serialized
* @return array
Expand All @@ -57,7 +55,7 @@ public function resolveDetails($serialized)
}

/**
* Return the attributes list
* Return the attributes list.
*
* @param $request
* @return array
Expand All @@ -77,7 +75,7 @@ public function resolveIndexMeta($request)
}

/**
* Return a list with relationship for the current model
* Return a list with relationship for the current model.
*
* @param $request
* @return array
Expand Down
4 changes: 0 additions & 4 deletions src/Traits/InteractWithSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace Binaryk\LaravelRestify\Traits;

use Binaryk\LaravelRestify\Http\Requests\RestifyRequest;
use Illuminate\Support\Str;

/**
* @author Eduard Lupacescu <eduard.lupacescu@binarcode.com>
*/
Expand Down Expand Up @@ -53,5 +50,4 @@ public static function getOrderByFields()
{
return static::$sort ?? [];
}

}