1trait RespondsWithHttpStatus
2{
3 protected function success($message, $data = [], $status = 200)
4 {
5 return response([
6 'success' => true,
7 'data' => $data,
8 'message' => $message,
9 ], $status);
10 }
11
12 protected function failure($message, $status = 422)
13 {
14 return response([
15 'success' => false,
16 'message' => $message,
17 ], $status);
18 }
19}
1When declaring resource routes that will be consumed by APIs,
2you will commonly want to exclude routes that present HTML
3templates such as "create" and "edit"
4
5//Route=>
6use App\Http\Controllers\PhotoController;
7Route::apiResource('photos', PhotoController::class);
8
9//artisan command =>
10php artisan make:controller PhotoController --api
11
1GET - "/photos/{photo}/comments" - index
2GET - "/photos/{photo}/comments/create" - create
3POST - "/photos/{photo}/comments" - store
4GET - "/comments/{comment}" - show
5GET - "/comments/{comment}/edit" - edit
6PUT/PATCH - "/comments/{comment}" - update
7DELETE - "/comments/{comment}" - destroy