Use response()->noContent() in RESTful API destroy and update endpoints to return semantic HTTP 204 responses cleanly.
In REST API design, when a resource deletion (DELETE) or background update successfully completes without returning a response body, returning HTTP 204 No Content is the standard convention.
Instead of writing return response('', 204);, Laravel provides the expressive response()->noContent() helper.
Basic Usage in API Controllers
use App\Models\Post;
use Illuminate\Http\Response;
public function destroy(Post $post): Response
{
$post->delete();
// Returns HTTP 204 with an empty response body
return response()->noContent();
}
Custom Status Codes and Headers
noContent() accepts a custom status code as the first argument (defaults to 204) and response headers as the second:
return response()->noContent(204, [
'X-Action-Completed' => 'true',
]);
Summary
- Returns an empty
Illuminate\Http\Responsewith HTTP status code 204. - Follows RESTful API standards for resource deletions and state updates.
- Expressive and self-documenting syntax for backend API controllers.
Related Tips
View all tips →Handle Hybrid API and Web Controllers with $request->expectsJson()
Use $request->expectsJson() in hybrid controllers to serve formatted JSON responses to API/AJAX requests and redirects to standard web browsers.
Authenticate External API Requests Cleanly with withToken()
Use withToken() on the Laravel HTTP client to attach Authorization Bearer tokens without manual header string formatting.