PHPackages                             charlesuwaje/response-macros - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. charlesuwaje/response-macros

ActiveLibrary[API Development](/categories/api)

charlesuwaje/response-macros
============================

Standard API response macros for Laravel

v1.0.0(1mo ago)36[1 PRs](https://github.com/Charlesuwaje/laravel-response-macros/pulls)MITPHPPHP ^8.1

Since Jun 24Pushed 1mo agoCompare

[ Source](https://github.com/Charlesuwaje/laravel-response-macros)[ Packagist](https://packagist.org/packages/charlesuwaje/response-macros)[ RSS](/packages/charlesuwaje-response-macros/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (3)Versions (5)Used By (0)

Response Macros for Laravel
===========================

[](#response-macros-for-laravel)

A lightweight Laravel package that provides reusable JSON response macros to keep your API responses consistent and developer-friendly.

---

Installation
------------

[](#installation)

```
composer require charlesuwaje/response-macros
```

Laravel will auto-discover the service provider. No manual registration needed.

---

Available Macros
----------------

[](#available-macros)

MacroStatusDescription`response()->success($message, $data, $status)`200Standard success response`response()->created($message, $data)`201Resource created`response()->accepted($message, $data)`202Request accepted (async/queued)`response()->noContent()`204Empty success response`response()->error($message, $data, $status)`400Generic error`response()->unauthorized($message, $data)`401Not authenticated`response()->forbidden($message, $data)`403Lacks permission`response()->notFound($message, $data)`404Resource not found`response()->methodNotAllowed($message, $data)`405HTTP method not allowed`response()->conflict($message, $data)`409Conflict (e.g. duplicate resource)`response()->validationError($message, $errors)`422Validation failed`response()->tooManyRequests($message, $data)`429Rate limit exceeded`response()->serverError($message, $data)`500Internal server error`response()->serviceUnavailable($message, $data)`503Service unavailable`response()->paginated($message, $data, $pagination)`200Paginated success response---

Usage
-----

[](#usage)

```
use App\Models\User;
use Illuminate\Http\Request;

class UserController extends Controller
{
    public function index()
    {
        $users = User::paginate(15);

        return response()->paginated('Users retrieved successfully', $users->items(), [
            'total'        => $users->total(),
            'per_page'     => $users->perPage(),
            'current_page' => $users->currentPage(),
            'last_page'    => $users->lastPage(),
        ]);
    }

    public function store(Request $request)
    {
        $validated = $request->validate([
            'name' => 'required|string|max:255',
        ]);

        $user = User::create($validated);

        return response()->created('User created successfully', $user->toArray());
    }

    public function show($id)
    {
        $user = User::find($id);

        if (! $user) {
            return response()->notFound('User not found');
        }

        return response()->success('User found', $user->toArray());
    }

    public function destroy($id)
    {
        $user = User::find($id);

        if (! $user) {
            return response()->notFound('User not found');
        }

        $user->delete();

        return response()->noContent();
    }
}
```

---

Response Format
---------------

[](#response-format)

**Success:**

```
{
    "status": "success",
    "message": "Users retrieved successfully",
    "data": []
}
```

**Paginated:**

```
{
    "status": "success",
    "message": "Users retrieved successfully",
    "data": [],
    "meta": {
        "pagination": {
            "total": 100,
            "per_page": 15,
            "current_page": 1,
            "last_page": 7
        }
    }
}
```

**Error:**

```
{
    "status": "error",
    "message": "Something went wrong",
    "data": {}
}
```

**Validation error:**

```
{
    "status": "validation_error",
    "message": "Validation failed",
    "errors": {
        "email": ["The email field is required."]
    }
}
```

---

Contributing
------------

[](#contributing)

PRs and suggestions are welcome. If you find a bug or want to add new macros, open an issue or submit a pull request.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance89

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

54d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/105389447?v=4)[charles uwaje](/maintainers/Charlesuwaje)[@Charlesuwaje](https://github.com/Charlesuwaje)

---

Top Contributors

[![Charlesuwaje](https://avatars.githubusercontent.com/u/105389447?v=4)](https://github.com/Charlesuwaje "Charlesuwaje (17 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/charlesuwaje-response-macros/health.svg)

```
[![Health](https://phpackages.com/badges/charlesuwaje-response-macros/health.svg)](https://phpackages.com/packages/charlesuwaje-response-macros)
```

###  Alternatives

[defstudio/telegraph

A laravel facade to interact with Telegram Bots

818355.4k3](/packages/defstudio-telegraph)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5226.7k](/packages/simplestats-io-laravel-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
