Skip to content

Commit 676c505

Browse files
authored
Merge pull request #6 from phpsa/develop
Develop merged into master for release 0.2
2 parents edc24d6 + 4ec1808 commit 676c505

16 files changed

+1586
-844
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ notifications:
88
on_failure: always
99

1010
php:
11-
- 7.0
1211
- 7.1
1312
- 7.2
1413

1514
env:
16-
- LARAVEL_VERSION=5.5.*
15+
- LARAVEL_VERSION=5.8.*
1716

1817
before_install:
1918
- travis_retry composer self-update --stable -n

README.md

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,21 @@ You can override the methods by simply putting in your own methods to override -
4040

4141
For the get command you can filter by using the following url patterns
4242

43-
| Seperator | Description | Example | Result |
44-
| --- | --- | --- | --- |
45-
| *`=`* | Equals | ?field=hello | select ... where field = 'hello' |
46-
| *`!=`* | Not Equals | ?field!=hello | select ... where field != 'hello' |
47-
| *`<>`* | Not Equals (alt) | ?field<>hello | select ... where field != 'hello' |
48-
| *`>`* | Greater Than | ?field>5 | select ... where field > 5 |
49-
| *`>=`* | Greater Or Equal to | ?field=>5 | select ... where field >= 5 |
50-
| *`<`* | Less Than | ?field<5 | select ... where field <> 5 |
51-
| *`<=`* | Less Or Equal to | ?field=<5 | select ... where field <= 5 |
52-
| *`~`* | Contains (LIKE with wildcard on both sides)| ?field~hello | select ... where field like '%hello%' |
53-
| *`^`* | Starts with (LIKE with wildcard on end)| ?field^hello | select ... where field like 'hello%' |
54-
| *`$`* | Ends with (LIKE with wildcard on start)| ?field$hello | select ... where field like 'hello%' |
55-
| *`!~`* | Not Contains (LIKE with wildcard on both sides)| ?field!~hello | select ... where field not like '%hello%' |
56-
| *`!^`* | Not Starts with (LIKE with wildcard on end)| ?field!^hello | select ... where field not like 'hello%' |
57-
| *`!$`* | Not Ends with (LIKE with wildcard on start)| ?field!$hello | select ... where field not like 'hello%' |
43+
| Seperator | Description | Example | Result |
44+
| --- | --- | --- | --- |
45+
| *`=`* | Equals | ?filter[field]=hello | select ... where field = 'hello' |
46+
| *`!=`* | Not Equals | ?filter[field!]=hello | select ... where field != 'hello' |
47+
| *`<>`* | Not Equals (alt) | ?filter[field<>]=hello | select ... where field != 'hello' |
48+
| *`>`* | Greater Than | ?filter[field>]=5 | select ... where field > 5 |
49+
| *`>=`* | Greater Or Equal to | ?filter[field=>]=5 | select ... where field >= 5 |
50+
| *`<`* | Less Than | ?filter[field<]=5 | select ... where field <> 5 |
51+
| *`<=`* | Less Or Equal to | ?filter[field=<]=5 | select ... where field <= 5 |
52+
| *`~`* | Contains (LIKE with wildcard on both sides) | ?filter[field~]=hello | select ... where field like '%hello%' |
53+
| *`^`* | Starts with (LIKE with wildcard on end) | ?filter[field^]=hello | select ... where field like 'hello%' |
54+
| *`$`* | Ends with (LIKE with wildcard on start) | ?filter[field$]=hello | select ... where field like 'hello%' |
55+
| *`!~`* | Not Contains (LIKE with wildcard on both sides) | ?filter[field!~]=hello | select ... where field not like '%hello%' |
56+
| *`!^`* | Not Starts with (LIKE with wildcard on end) | ?filter[field!^]=hello | select ... where field not like 'hello%' |
57+
| *`!$`* | Not Ends with (LIKE with wildcard on start) | ?filter[field!$]=hello | select ... where field not like 'hello%' |
5858

5959

6060
# Fields, Relationships, Sorting & Pagination
@@ -80,8 +80,28 @@ By default all fields are returned, you can limit that to specific fields in the
8080
* pagination can also be passed via the url using `limit=xx&page=y`
8181
* pagination can also be limited to a max per page by overriding the `protected $maximumLimit = false;` parameter
8282

83+
## Validation
84+
* When Posting a new record, validation can be done by adding a `rulesForCreate` method to your controller returning an array eg
85+
```php
86+
[
87+
'email' => 'required|email',
88+
'games' => 'required|numeric',
89+
]
90+
```
91+
see https://laravel.com/docs/5.8/validation#conditionally-adding-rules
92+
* for updating a record, add a method `rulesForUpdate` per above.
93+
94+
## Defaults
8395

96+
The following parameters are set in the Base Api controller and can be overwritten by your Controller on a case by case basis:
8497

98+
* `protected $resourceKeySingular = 'data';` Resource key for an item.
99+
* `protected $resourceKeyPlural = 'data';` Resource key for a collection.
100+
* `protected $defaultFields = ['*'];` Default Fields to respond with
101+
* `protected $defaultSort = null;` Set the default sorting for queries.
102+
* `protected $defaultLimit = 25;` Number of items displayed at once if not specified. (0 = maximumLimit)
103+
* `protected $maximumLimit = 0;` Maximum limit that can be set via $_GET['limit']. - this ties in with the defaultLimit aswell, and if wanting to disable pagination , both should be 0. ) will allow all records to be returned in a single call.
104+
* `protected $unguard = false;` Do we need to unguard the model before create/update?
85105

86106
## Security
87107

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
],
1717
"require": {
1818
"php": ">=7.1.3",
19-
"illuminate/support": "~5.8.0"
19+
"illuminate/support": "~5.8.0|~6.0.0"
2020
},
2121
"require-dev": {
2222
"orchestra/testbench": "~3.8.0",

config/laravel-api-controller.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<?php
2+
23
return [
34
/*
45
* Relative path from the app directory to api controllers directory.
56
*/
6-
'controllers_dir' => 'Http/Controllers/Api',
7-
/*
8-
* Relative path from the app directory to api repositories directory.
9-
*/
10-
'repositorys_dir' => 'Repositories/Api',
7+
'controllers_dir' => 'Http/Controllers/Api',
118
/*
129
* Relative path from the app directory to the api routes file.
1310
*/
@@ -19,14 +16,19 @@
1916
/*
2017
* Relative path from the base directory to the api controller stub.
2118
*/
22-
'controller_stub' => 'vendor/phpsa/laravel-api-controller/src/Generator/stubs/controller.stub',
23-
/*
24-
* Relative path from the base directory to the api controller stub.
25-
*/
26-
'repository_stub' => 'vendor/phpsa/laravel-api-controller/src/Generator/stubs/repository.stub',
19+
'controller_stub' => 'vendor/phpsa/laravel-api-controller/src/Generator/stubs/controller.stub',
2720
/*
2821
* Relative path from the base directory to the route stub.
2922
*/
3023
'route_stub' => 'vendor/phpsa/laravel-api-controller/src/Generator/stubs/route.stub',
3124

32-
];
25+
'parameters' => [
26+
'include' => 'include',
27+
'filter' => 'filter',
28+
'sort' => 'sort',
29+
'fields' => 'fields',
30+
'page' => 'page',
31+
'group' => 'group',
32+
],
33+
34+
];

src/Exceptions/ApiException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
use Exception;
66

7-
Class ApiException extends Exception {
8-
9-
}
7+
class ApiException extends Exception
8+
{
9+
}

src/Exceptions/UnknownColumnException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
use Exception;
66

7-
Class UnknownColumnException extends Exception {
8-
9-
}
7+
class UnknownColumnException extends Exception
8+
{
9+
}

0 commit comments

Comments
 (0)