Skip to content

Commit 4b60f51

Browse files
committed
m
0 parents  commit 4b60f51

20 files changed

+5272
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/vendor
2+
.idea
3+
.phpintel

Readme.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
## Installation
2+
```
3+
composer require essa/api_generator:dev-master
4+
```
5+
6+
7+
8+
### Exceptions:
9+
10+
`App\Providers\Handler.php`:
11+
12+
```php
13+
14+
15+
16+
use Throwable;
17+
use essa\APIGenerator\Http\ApiResponse;
18+
use Illuminate\Database\QueryException;
19+
use Illuminate\Validation\ValidationException;
20+
use Illuminate\Auth\Access\AuthorizationException;
21+
use Illuminate\Database\Eloquent\ModelNotFoundException;
22+
23+
class Handler extends ExceptionHandler
24+
{
25+
use ApiResponse;
26+
27+
/**
28+
* Render an exception into an HTTP response.
29+
*
30+
* @param \Illuminate\Http\Request $request
31+
* @param \Throwable $exception
32+
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response
33+
* @throws \Throwable
34+
*/
35+
public function render($request, Throwable $exception)
36+
{
37+
if ($exception instanceof ValidationException) {
38+
return $this->ResponseValidationError($exception);
39+
}
40+
41+
if ($exception instanceof QueryException || $exception instanceof ModelNotFoundException) {
42+
return $this->responseNotFound("Record not found!", $exception->getMessage());
43+
}
44+
45+
if ($exception instanceof AuthorizationException) {
46+
return $this->responseUnauthorized();
47+
}
48+
49+
return parent::render($request, $exception);
50+
}
51+
}
52+
53+
54+
```
55+
56+
### Controller:
57+
58+
`App\Http\Controllers\Controller.php`:
59+
60+
```php
61+
use essa\APIGenerator\Http\ApiResponse;
62+
63+
class Controller extends BaseController
64+
{
65+
use ApiResponse;
66+
}
67+
```
68+
69+
70+
71+
## Usage
72+
73+
Create component
74+
```
75+
php artisan make:module Admin
76+
```
77+
78+
```
79+
php artisan make:module Admin --with-image
80+
```

composer.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "essa/api_generator",
3+
"type": "library",
4+
"license": "MIT",
5+
"authors": [
6+
{
7+
"name": "ahmedesa",
8+
"email": "ahmedesa1997@gmail.com"
9+
}
10+
],
11+
"require": {
12+
"php": "^7.0 || ^7.1 || ^7.2 || ^7.3 || ^7.4",
13+
"spatie/laravel-query-builder": "^3.3"
14+
},
15+
"require-dev": {
16+
"laravel/framework": "^5.5 || ^6.0 || ^7.0 || ^8.0"
17+
},
18+
"minimum-stability": "dev",
19+
"prefer-stable": true,
20+
"autoload": {
21+
"psr-4": {
22+
"essa\\APIGenerator\\": "src/"
23+
}
24+
},
25+
"extra": {
26+
"laravel": {
27+
"providers": [
28+
"essa\\APIGenerator\\APIGeneratorServiceProvider"
29+
]
30+
}
31+
},
32+
"description": ""
33+
}

0 commit comments

Comments
 (0)