Skip to content

Commit f15462a

Browse files
samatcdphpsa
authored andcommitted
Logic inversion (#35)
* Develop (#33) * Added Created, Updated and Deleted events, Moved request to each method to allow overloading: * Apply fixes from StyleCI * Scrutinizer updates * Update controller.stub * Feature/requests mapping (#13) * Event accepts request object and any type of request can now be pushed through * Apply fixes from StyleCI (#12) * Request should have a constructor for instances with models * Update BaseRepository.php * Apply fixes from StyleCI (#15) * Fixed namespace type declaration * Fixed namespace type declaration * Fixed namespace type declaration * Feature/requests mapping (#17) * Event accepts request object and any type of request can now be pushed through * Apply fixes from StyleCI (#12) * Request should have a constructor for instances with models * Update BaseRepository.php * Apply fixes from StyleCI (#18) * Feature/policy collections update (#19) * Develop (#14) * Added Created, Updated and Deleted events, Moved request to each method to allow overloading: * Apply fixes from StyleCI * Scrutinizer updates * Update controller.stub * Feature/requests mapping (#13) * Event accepts request object and any type of request can now be pushed through * Apply fixes from StyleCI (#12) * Request should have a constructor for instances with models * Update BaseRepository.php * Apply fixes from StyleCI (#15) * Fixed namespace type declaration * Fixed namespace type declaration * Fixed namespace type declaration * Develop To Master (#16) * Added Created, Updated and Deleted events, Moved request to each method to allow overloading: * Apply fixes from StyleCI * Scrutinizer updates * Update controller.stub * Feature/requests mapping (#13) * Event accepts request object and any type of request can now be pushed through * Apply fixes from StyleCI (#12) * Request should have a constructor for instances with models * Update BaseRepository.php * Apply fixes from StyleCI (#15) * Fixed namespace type declaration * Fixed namespace type declaration * Fixed namespace type declaration * Added resource collections and policy check. * Updated Readme * Formatting * Apply fixes from StyleCI (#20) * Scrutinizer fixes - deprecation / namesapce * Feature/policy collections update (#22) * Develop (#14) * Added Created, Updated and Deleted events, Moved request to each method to allow overloading: * Apply fixes from StyleCI * Scrutinizer updates * Update controller.stub * Feature/requests mapping (#13) * Event accepts request object and any type of request can now be pushed through * Apply fixes from StyleCI (#12) * Request should have a constructor for instances with models * Update BaseRepository.php * Apply fixes from StyleCI (#15) * Fixed namespace type declaration * Fixed namespace type declaration * Fixed namespace type declaration * Develop To Master (#16) * Added Created, Updated and Deleted events, Moved request to each method to allow overloading: * Apply fixes from StyleCI * Scrutinizer updates * Update controller.stub * Feature/requests mapping (#13) * Event accepts request object and any type of request can now be pushed through * Apply fixes from StyleCI (#12) * Request should have a constructor for instances with models * Update BaseRepository.php * Apply fixes from StyleCI (#15) * Fixed namespace type declaration * Fixed namespace type declaration * Fixed namespace type declaration * Added resource collections and policy check. * Updated Readme * Formatting * Apply fixes from StyleCI (#20) * Scrutinizer fixes - deprecation / namesapce * Added middleware and query qualifiers * Policy Update * Post adding new and artisan updated, code cleanup * Apply fixes from StyleCI (#21) * Scrutiniser fixes * Put now handles relations * Fix return types * Minor updates to fix relationships and make command * Sanke case vs camel case * Apply fixes from StyleCI (#23) * Minor bugfix for case sensitifity * Fixed make command * model is static * Apply fixes from StyleCI (#24) * Scrutiniser fixes * Apply fixes from StyleCI (#25) * Apply fixes from StyleCI (#27) * Policiies auth mehtod without users * user not needed * Tidy up uri parser class * Fixes * fix more * Feature/policy collections update (#29) * Added resource collections and policy check. * Updated Readme * Formatting * Apply fixes from StyleCI (#20) * Scrutinizer fixes - deprecation / namesapce * Added middleware and query qualifiers * Policy Update * Post adding new and artisan updated, code cleanup * Apply fixes from StyleCI (#21) * Scrutiniser fixes * Put now handles relations * Fix return types * Minor updates to fix relationships and make command * Sanke case vs camel case * Apply fixes from StyleCI (#23) * Minor bugfix for case sensitifity * Fixed make command * model is static * Apply fixes from StyleCI (#24) * Scrutiniser fixes * policies - for unauthed users * Minor updates * STYLEFIXES * fixed phpcs rule * Apply fixes from StyleCI (#31) * Feature/policy collections update (#32) * Added resource collections and policy check. * Updated Readme * Formatting * Apply fixes from StyleCI (#20) * Scrutinizer fixes - deprecation / namesapce * Added middleware and query qualifiers * Policy Update * Post adding new and artisan updated, code cleanup * Apply fixes from StyleCI (#21) * Scrutiniser fixes * Put now handles relations * Fix return types * Minor updates to fix relationships and make command * Sanke case vs camel case * Apply fixes from StyleCI (#23) * Minor bugfix for case sensitifity * Fixed make command * model is static * Apply fixes from StyleCI (#24) * Scrutiniser fixes * policies - for unauthed users * Minor updates * STYLEFIXES * fixed phpcs rule * Apply fixes from StyleCI (#31) * minor updates * csfixer run on code * Missing file updated * Includes should be returnable * static not defined * Allowed fields updated * minor updates * Logic inversion + Updated excludeArrayValues to exclude if not in optionals instead of always including. * Added accessor notes about $appends usage * Update controller with query modifier * Add extra query parser method * Include previous exception with ApiException
1 parent 26eb667 commit f15462a

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ By default all fields are returned, you can limit that to specific fields in the
120120
* Api Controller parameter `$defaultFields` default as `protected $defaultFields = ['*'];` - switch to include an array of fields
121121
* fields param in url querystring: ie `fields=id,name,age` = will only return those, this will also override the above.
122122
* in your response resource you can set the static::allowedFields to lock down which fields are returnable
123-
* addfields and removefields params in url querystring will work with these.
123+
* `addfields` and `removefields` params in url querystring will work with these.
124+
* Use laravel [eloquent model `$appends`](https://laravel.com/docs/6.x/eloquent-serialization#appending-values-to-json) property to automatically include custom attribute accessors.
124125

125126
## Relationships
126127

src/Contracts/Parser.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ protected function getUriParser($request)
2323
return self::$uriParser;
2424
}
2525

26+
protected function parseExtraQueryParams($request, array $extraParams = []): void
27+
{
28+
$all = $request->query->all();
29+
$new = array_merge_recursive($all, $extraParams);
30+
$request->query->add($new);
31+
}
32+
2633
/**
2734
* Parses our include joins.
2835
*/

src/Helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public static function filterFieldsFromRequest($request, ?array $defaultFields,
117117
public static function excludeArrayValues(array $array, array $excludes, ?array $optionals = []): array
118118
{
119119
return Arr::where($array, function ($value) use ($excludes, $optionals) {
120-
return ! in_array($value, $excludes) || in_array($value, $optionals);
120+
return ! in_array($value, $excludes) || ! in_array($value, $optionals);
121121
});
122122
}
123123
}

src/Http/Controllers/Api/Controller.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ public function __construct()
105105
*
106106
* @param \Illuminate\Http\Request|\Illuminate\Foundation\Http\FormRequest $request
107107
*/
108-
public function handleIndexAction($request)
108+
public function handleIndexAction($request, array $extraParams = [])
109109
{
110+
$this->parseExtraQueryParams($request, $extraParams);
110111
$this->validateRequestType($request);
111112
$this->authoriseUserAction('viewAny');
112113
$this->getUriParser($request);
@@ -168,7 +169,7 @@ public function handleStoreAction($request)
168169
} catch (\Illuminate\Database\QueryException $exception) {
169170
$message = config('app.debug') ? $exception->getMessage() : 'Failed to create Record';
170171

171-
throw new ApiException($message);
172+
throw new ApiException($message, $exception->getCode(), $exception);
172173
} catch (\Exception $exception) {
173174
DB::rollback();
174175

@@ -183,8 +184,9 @@ public function handleStoreAction($request)
183184
* @param int $id
184185
* @param \Illuminate\Http\Request|\Illuminate\Foundation\Http\FormRequest $request
185186
*/
186-
public function handleShowAction($id, $request)
187+
public function handleShowAction($id, $request, array $extraParams = [])
187188
{
189+
$this->parseExtraQueryParams($request, $extraParams);
188190
$this->validateRequestType($request);
189191

190192
$this->authoriseUserAction('view', self::$model::find($id));

0 commit comments

Comments
 (0)