-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding index query and make static filters
- Loading branch information
Showing
14 changed files
with
256 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace Binaryk\LaravelRestify\Http\Requests; | ||
|
||
use Binaryk\LaravelRestify\Exceptions\Eloquent\EntityNotFoundException; | ||
use Binaryk\LaravelRestify\Exceptions\UnauthorizedException; | ||
use Binaryk\LaravelRestify\Repositories\Repository; | ||
use Binaryk\LaravelRestify\Restify; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
/** | ||
* @package Binaryk\LaravelRestify\Http\Requests; | ||
* @author Eduard Lupacescu <[email protected]> | ||
*/ | ||
trait InteractWithRepositories | ||
{ | ||
/** | ||
* @var Model | ||
*/ | ||
public $model; | ||
|
||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the class name of the repository being requested. | ||
* | ||
* @return Repository | ||
* @throws EntityNotFoundException | ||
* @throws UnauthorizedException | ||
*/ | ||
public function repository() | ||
{ | ||
return tap(Restify::repositoryForKey($this->route('repository')), function ($repository) { | ||
if (is_null($repository)) { | ||
throw new EntityNotFoundException(__('Repository :name not found.', [ | ||
'name' => $repository, | ||
]), 404); | ||
} | ||
|
||
if ( ! $repository::authorizedToViewAny($this)) { | ||
throw new UnauthorizedException(__('Unauthorized to view repository :name.', [ | ||
'name' => $repository, | ||
]), 403); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,48 +2,13 @@ | |
|
||
namespace Binaryk\LaravelRestify\Http\Requests; | ||
|
||
use Binaryk\LaravelRestify\Exceptions\Eloquent\EntityNotFoundException; | ||
use Binaryk\LaravelRestify\Exceptions\UnauthorizedException; | ||
use Binaryk\LaravelRestify\Repositories\Repository; | ||
use Binaryk\LaravelRestify\Restify; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
/** | ||
* @author Eduard Lupacescu <[email protected]> | ||
*/ | ||
class RestifyRequest extends FormRequest | ||
{ | ||
/** | ||
* Get the class name of the repository being requested. | ||
* | ||
* @return Repository | ||
*/ | ||
public function repository() | ||
{ | ||
return tap(Restify::repositoryForKey($this->route('repository')), function ($repository) { | ||
if (is_null($repository)) { | ||
throw new EntityNotFoundException(__('Repository :name not found.', [ | ||
'name' => $repository, | ||
]), 404); | ||
} | ||
use InteractWithRepositories; | ||
|
||
if (! $repository::authorizedToViewAny($this)) { | ||
throw new UnauthorizedException(__('Unauthorized to view repository :name.', [ | ||
'name' => $repository, | ||
]), 403); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.