Skip to content

Instantly share code, notes, and snippets.

@whoisryosuke
Forked from hanspagel/ProjectController.php
Last active June 1, 2018 17:33
Show Gist options
  • Select an option

  • Save whoisryosuke/76416be0c935b1cfb84536b48866e3e5 to your computer and use it in GitHub Desktop.

Select an option

Save whoisryosuke/76416be0c935b1cfb84536b48866e3e5 to your computer and use it in GitHub Desktop.
Laravel - API - How to return API Resources with different status codes
<?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