Skip to content
This repository was archived by the owner on Aug 27, 2024. It is now read-only.

Commit 3404df4

Browse files
authored
Merge pull request #17 from Saritasa/feature/add-typical-requests
Add typical requests
2 parents 90fec94 + 7444001 commit 3404df4

15 files changed

+122
-2249
lines changed

.github/workflows/phpunit.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
with:
1919
php-version: ${{ matrix.php-versions }}
2020
coverage: xdebug
21-
21+
2222
- name: Check PHP Version
2323
run: php -v
2424

@@ -30,11 +30,11 @@ jobs:
3030

3131
- name: Run test suite
3232
run: vendor/bin/phpunit --coverage-clover=coverage.xml
33-
33+
3434
- name: Upload Codecov
3535
uses: codecov/codecov-action@v1
3636
with:
3737
file: ./coverage.xml
3838
flags: unittests
3939
fail_ci_if_error: false
40-
verbose: true
40+
verbose: true

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
package.xml
33
/vendor
44
.idea
5+
*.cache

CHANGES.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changes History
22

3+
4.0.0
4+
-----
5+
+ Add PageRequest, ChangePassword request
6+
+ Depend on [saritasa/laravel-fluent-validation](https://github.com/Saritasa/php-laravel-fluent-validation) and [saritasa/dingo-api-custom](https://github.com/Saritasa/php-dingo-api-custom)
7+
+ Remove ApiResourceRegistrar and WebResourceRegistrar (standard router is enough)
8+
39
3.3.5
410
-----
511
Require release tymon/jwt-auth version instead of RC

README.md

+22-76
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,23 @@ Recommended to use as base controller for other API controllers.
3333

3434
#### Methods
3535
* function json($data, IDataTransformer $transformer = null): Response
36-
* function validate(Request $request, array $rules, array $messages = [], array $customAttributes = [])
3736

3837
**Example**:
3938
```php
4039
class UserApiController extends BaseApiController
4140
{
42-
public function __construct(UserTransformer $userTransformer)
43-
{
44-
parent::__construct($userTransformer);
45-
}
46-
public function editUserProfile(Request $request, User $user): Response
47-
{
48-
$this->validate($request, $user->getRuels());
49-
$user->fill($request->all());
50-
$user->save();
51-
return $this->json($user);
52-
}
41+
public function __construct(UserTransformer $userTransformer)
42+
{
43+
parent::__construct($userTransformer);
44+
}
45+
46+
public function editUserProfile(Request $request, User $user): Response
47+
{
48+
$this->validate($request, $user->getRuels());
49+
$user->fill($request->all());
50+
$user->save();
51+
return $this->json($user);
52+
}
5353
}
5454
```
5555
### JWTAuthApiController Authenticate API Controller. Uses JWT authentication
@@ -59,77 +59,23 @@ settings and underlying [tymon\jwt-auth](https://github.com/tymondesigns/jwt-aut
5959
**Example**: routes\api.php:
6060
```php
6161
app('api.router')->version(config('api.version'), ['namespace' => 'Saritasa\Laravel\Controllers\Api'],
62-
function (\Dingo\Api\Routing\Router $api) {
63-
// Authentication $api->post('auth', 'AuthController@login'); // Login $api->put('auth', 'AuthController@refreshToken'); // Refresh expired token
64-
$api->delete('auth', 'AuthController@logout')->middleware('api.auth'); // Logout
65-
});
62+
function (\Dingo\Api\Routing\Router $api) {
63+
// Authentication $api->post('auth', 'AuthController@login'); // Login $api->put('auth', 'AuthController@refreshToken'); // Refresh expired token
64+
$api->delete('auth', 'AuthController@logout')->middleware('api.auth'); // Logout
65+
});
6666
```
67-
### ResourceApiController
68-
Controller for typical CRUD operations when you don't need many additional logic.
69-
For using this functionality you can just create controller and set needed model class in property $modelClass
70-
**Example**:
71-
```php
72-
class CustomApiController extends ResourceApiController
73-
{
74-
/**
75-
* Define model class that is managed by this controller.
76-
*
77-
* @var string
78-
*/
79-
protected $modelClass = App\Models\User::class;
80-
}
81-
```
67+
8268
### ForgotPasswordApiController, ResetPasswordApiController These controllers are responsible for handling password reset emails.
8369
Utilize native Laravel password management without UI, in JSON API.
8470

8571
**Example**: routes\api.php:
8672
```php
87-
app('api.router')->version(config('api.version'), ['namespace' => 'Saritasa\Laravel\Controllers\Api'],
88-
function (\Dingo\Api\Routing\Router $api) { $api->post('auth/password/reset', 'ForgotPasswordApiController@sendResetLinkEmail'); $api->put('auth/password/reset', 'ResetPasswordApiController@reset');});
89-
```
90-
## Routes registration examples:
91-
### Simple route
92-
```php
93-
$registrar->get('users', ApiController::class, 'list');
73+
app('api.router')->version(config('api.version'), ['namespace' => 'Saritasa\Laravel\Controllers\Api'],
74+
function (\Dingo\Api\Routing\Router $api) {
75+
$api->post('auth/password/reset', 'ForgotPasswordApiController@sendResetLinkEmail');
76+
$api->put('auth/password/reset', 'ResetPasswordApiController@reset');
77+
});
9478
```
95-
In this case ApiController::list will be calling with default dependency injection.
96-
97-
### Route with parameters
98-
```php
99-
// Controller example
100-
class ApiController {
101-
public function show(int $id) {}
102-
}
103-
// Route example
104-
$registrar->get('users/{id}', ApiController::class, 'show');
105-
```
106-
In this case ApiController::show will receive directly parameter from url. Ex: /user/5
107-
108-
### Route with binding on controller side
109-
```php
110-
// Controller example
111-
class ApiController {
112-
public function show(User $user) {}
113-
}
114-
// Route example
115-
$registrar->get('users/{user}', ApiController::class, 'show');
116-
```
117-
In this case ApiController::show try to find Model user by id and if not exists throws ModelNotFoundException.
118-
119-
### Route with binding on route side
120-
```php
121-
// Controller example
122-
class ApiController {
123-
public function show(Model $user) {}
124-
}
125-
// Route example
126-
$registrar->get('users/{user}', ApiController::class, 'show', null, ['user' => User::class]);
127-
```
128-
In this case no matter what type hint in controller, container will be trying to give object of class that you pass in router registrar.
129-
So if method has type hinting of class which not a parent for given in router, TypeError will be thrown.
130-
131-
#### Note: In 2 last cases classes which uses for model bindings must implement Illuminate\Contracts\Routing\UrlRoutable otherwise this parameters
132-
will be ignored.
13379

13480
## Contributing
13581
1. Create fork, checkout it

composer.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@
1313
"require": {
1414
"php": ">=7.1",
1515
"ext-json": "*",
16-
"illuminate/support": "^5.7 || ^6.0",
16+
"illuminate/http": "^5.7 | 6.*",
17+
"illuminate/support": "^5.7 | 6.*",
18+
"saritasa/dingo-api-custom": "^2.2",
19+
"saritasa/laravel-fluent-validation": "^1.2",
1720
"saritasa/transformers": "^1.0",
18-
"tymon/jwt-auth": "^1.0",
19-
"saritasa/laravel-entity-services": "^1.3"
21+
"tymon/jwt-auth": "^1.0"
2022
},
2123
"require-dev": {
2224
"mockery/mockery": "^1.1",
23-
"phpunit/phpunit": "^7.5",
25+
"phpunit/phpunit": ">=6.0",
2426
"squizlabs/php_codesniffer": "^3.0"
2527
},
2628
"minimum-stability": "beta",

0 commit comments

Comments
 (0)