Skip to content

Commit b857475

Browse files
Merge pull request #1 from ManiruzzamanAkash/migrate-laravel-9
Upgrade to Laravel 9.x
2 parents 8cf426c + 476c9ea commit b857475

File tree

8 files changed

+1987
-3423
lines changed

8 files changed

+1987
-3423
lines changed

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ Basic Laravel CRUD API application included with Authentication Module & Product
44
----
55

66
### Language & Framework Used:
7-
1. PHP
8-
1. Laravel
7+
1. PHP-8
8+
1. Laravel-9
9+
10+
### Older Versions (if Needed):
11+
1. Laravel 8.x - https://github.com/ManiruzzamanAkash/Laravel-Advanced-CRUD-API/releases/tag/vLaravel8.x
912

1013
### Architecture Used:
14+
1. Laravel 9.x
1115
1. Interface-Repository Pattern
1216
1. Model Based Eloquent Query
1317
1. Swagger API Documentation - https://github.com/DarkaOnLine/L5-Swagger
@@ -35,22 +39,26 @@ Basic Laravel CRUD API application included with Authentication Module & Product
3539
```bash
3640
git clone https://github.com/ManiruzzamanAkash/Laravel-Basic-CRUD-API.git
3741
```
38-
2. Go to the project drectory by `cd Laravel-Basic-CRUD-API` & Run the
42+
1. Go to the project drectory by `cd Laravel-Basic-CRUD-API` & Run the
3943
2. Create `.env` file & Copy `.env.example` file to `.env` file
4044
3. Create a database called - `laravel_basic_crud`.
4145
4. Now migrate and seed database to complete whole project setup by running this-
4246
``` bash
4347
php artisan migrate:refresh --seed
4448
```
4549
It will create `21` Users and `103` Dummy Products.
46-
5. Run the server -
50+
5. Generate Swagger API
51+
``` bash
52+
php artisan l5-swagger:generate
53+
```
54+
6. Run the server -
4755
``` bash
4856
php artisan serve
4957
```
50-
6. Open Browser -
58+
7. Open Browser -
5159
http://127.0.0.1:8000 & go to API Documentation -
5260
http://127.0.0.1:8000/api/documentation
53-
7. You'll see a Swagger Panel.
61+
8. You'll see a Swagger Panel.
5462

5563

5664
### Procedure

app/Http/Controllers/Products/ProductsController.php

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@
1010
use App\Repositories\ResponseRepository;
1111
use Illuminate\Http\Response;
1212

13+
/**
14+
* @OA\Info(
15+
* description="API Documentation - Basic CRUD Laravel",
16+
* version="1.0.0",
17+
* title="Basic CRUD Laravel API Documentation",
18+
* @OA\Contact(
19+
20+
* ),
21+
* @OA\License(
22+
* name="GPL2",
23+
* url="https://devsenv.com"
24+
* )
25+
* )
26+
*/
27+
1328
class ProductsController extends Controller
1429
{
1530
public $productRepository;
@@ -44,16 +59,15 @@ public function index()
4459
}
4560
}
4661

47-
4862
/**
4963
* @OA\GET(
5064
* path="/api/products/view/all",
5165
* tags={"Products"},
52-
* summary="All Products - Publicly Accessable",
53-
* description="All Products - Publicly Accessable",
66+
* summary="All Products - Publicly Accessible",
67+
* description="All Products - Publicly Accessible",
5468
* operationId="indexAll",
5569
* @OA\Parameter(name="perPage", description="perPage, eg; 20", example=20, in="query", @OA\Schema(type="integer")),
56-
* @OA\Response(response=200, description="All Products - Publicly Accessable" ),
70+
* @OA\Response(response=200, description="All Products - Publicly Accessible" ),
5771
* @OA\Response(response=400, description="Bad request"),
5872
* @OA\Response(response=404, description="Resource Not Found"),
5973
* )
@@ -67,17 +81,17 @@ public function indexAll(Request $request)
6781
return $this->responseRepository->ResponseError(null, $e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
6882
}
6983
}
70-
84+
7185
/**
7286
* @OA\GET(
7387
* path="/api/products/view/search",
7488
* tags={"Products"},
75-
* summary="All Products - Publicly Accessable",
76-
* description="All Products - Publicly Accessable",
89+
* summary="All Products - Publicly Accessible",
90+
* description="All Products - Publicly Accessible",
7791
* operationId="search",
7892
* @OA\Parameter(name="perPage", description="perPage, eg; 20", example=20, in="query", @OA\Schema(type="integer")),
7993
* @OA\Parameter(name="search", description="search, eg; Test", example="Test", in="query", @OA\Schema(type="string")),
80-
* @OA\Response(response=200, description="All Products - Publicly Accessable" ),
94+
* @OA\Response(response=200, description="All Products - Publicly Accessible" ),
8195
* @OA\Response(response=400, description="Bad request"),
8296
* @OA\Response(response=404, description="Resource Not Found"),
8397
* )
@@ -141,7 +155,7 @@ public function show($id)
141155
{
142156
try {
143157
$data = $this->productRepository->getByID($id);
144-
if(is_null($data))
158+
if (is_null($data))
145159
return $this->responseRepository->ResponseError(null, 'Product Not Found', Response::HTTP_NOT_FOUND);
146160

147161
return $this->responseRepository->ResponseSuccess($data, 'Product Details Fetch Successfully !');
@@ -176,7 +190,7 @@ public function update(ProductRequest $request, $id)
176190
{
177191
try {
178192
$data = $this->productRepository->update($id, $request->all());
179-
if(is_null($data))
193+
if (is_null($data))
180194
return $this->responseRepository->ResponseError(null, 'Product Not Found', Response::HTTP_NOT_FOUND);
181195

182196
return $this->responseRepository->ResponseSuccess($data, 'Product Updated Successfully !');
@@ -201,12 +215,13 @@ public function update(ProductRequest $request, $id)
201215
public function destroy($id)
202216
{
203217
try {
204-
$produtData = $this->productRepository->getByID($id);
218+
$product = $this->productRepository->getByID($id);
205219
$deleted = $this->productRepository->delete($id);
206-
if(!$deleted)
220+
if (!$deleted) {
207221
return $this->responseRepository->ResponseError(null, 'Product Not Found', Response::HTTP_NOT_FOUND);
222+
}
208223

209-
return $this->responseRepository->ResponseSuccess($produtData, 'Product Deleted Successfully !');
224+
return $this->responseRepository->ResponseSuccess($product, 'Product Deleted Successfully !');
210225
} catch (\Exception $e) {
211226
return $this->responseRepository->ResponseError(null, $e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
212227
}

app/Http/Middleware/TrustProxies.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
namespace App\Http\Middleware;
44

5-
use Fideloper\Proxy\TrustProxies as Middleware;
5+
use Illuminate\Http\Middleware\TrustProxies as Middleware;
66
use Illuminate\Http\Request;
77

88
class TrustProxies extends Middleware
99
{
1010
/**
1111
* The trusted proxies for this application.
1212
*
13-
* @var array|string|null
13+
* @var array|string
1414
*/
1515
protected $proxies;
1616

@@ -19,5 +19,9 @@ class TrustProxies extends Middleware
1919
*
2020
* @var int
2121
*/
22-
protected $headers = Request::HEADER_X_FORWARDED_ALL;
22+
protected $headers = Request::HEADER_X_FORWARDED_FOR |
23+
Request::HEADER_X_FORWARDED_HOST |
24+
Request::HEADER_X_FORWARDED_PORT |
25+
Request::HEADER_X_FORWARDED_PROTO |
26+
Request::HEADER_X_FORWARDED_AWS_ELB;
2327
}
Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,2 @@
11
<?php
22

3-
/**
4-
* @OA\Info(
5-
* description="API Documentation - Basic CRUD Laravel",
6-
* version="1.0.0",
7-
* title="Basic CRUD Laravel API Documentation",
8-
* @OA\Contact(
9-
10-
* ),
11-
* @OA\License(
12-
* name="@ManiruzzamanAkash",
13-
* url="https://devsenv.com"
14-
* )
15-
* )
16-
*/

composer.json

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,21 @@
88
],
99
"license": "MIT",
1010
"require": {
11-
"php": "^7.3|^8.0",
12-
"darkaonline/l5-swagger": "^8.0",
13-
"fideloper/proxy": "^4.4",
14-
"fruitcake/laravel-cors": "^2.0",
15-
"guzzlehttp/guzzle": "^7.0.1",
16-
"laravel/framework": "^8.12",
17-
"laravel/tinker": "^2.5",
18-
"tymon/jwt-auth": "^1.0",
19-
"zircote/swagger-php": "^3.1"
11+
"php": "^8.0.2",
12+
"darkaonline/l5-swagger": "^8.3",
13+
"fruitcake/laravel-cors": "^3.0",
14+
"guzzlehttp/guzzle": "^7.2",
15+
"laravel/framework": "^9.2",
16+
"laravel/tinker": "^2.7",
17+
"tomfordrumm/jwt-auth": "dev-develop",
18+
"zircote/swagger-php": "^4.2"
2019
},
2120
"require-dev": {
22-
"facade/ignition": "^2.5",
23-
"fakerphp/faker": "^1.9.1",
24-
"laravel/sail": "^0.0.5",
25-
"mockery/mockery": "^1.4.2",
26-
"nunomaduro/collision": "^5.0",
27-
"phpunit/phpunit": "^9.3.3"
21+
"fakerphp/faker": "^1.19",
22+
"laravel/sail": "^1.13",
23+
"mockery/mockery": "^1.5",
24+
"nunomaduro/collision": "^6.1",
25+
"spatie/laravel-ignition": "^1.0"
2826
},
2927
"config": {
3028
"optimize-autoloader": true,

0 commit comments

Comments
 (0)