-
-
Save whoisryosuke/76416be0c935b1cfb84536b48866e3e5 to your computer and use it in GitHub Desktop.
Laravel - API - How to return API Resources with different status codes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Http\Controllers; | |
| use App\Models\Project; | |
| use Illuminate\Http\Request; | |
| class ProjectController extends Controller | |
| { | |
| public function update(Request $request, Project $project) | |
| { | |
| $project->update([ | |
| 'title' => $request->title, | |
| ]); | |
| // API Resource with `202 Accepted` Response | |
| return (new ProjectResource($project)) | |
| ->response() | |
| ->setStatusCode(202); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment