PHPackages                             fadyreda99/laravel-response - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. fadyreda99/laravel-response

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

fadyreda99/laravel-response
===========================

Reusable success/error response trait for Laravel projects

v1.0.5(5mo ago)111MITPHPPHP &gt;=8.0

Since Nov 30Pushed 5mo agoCompare

[ Source](https://github.com/fadyreda99/laravel-response)[ Packagist](https://packagist.org/packages/fadyreda99/laravel-response)[ RSS](/packages/fadyreda99-laravel-response/feed)WikiDiscussions master Synced 1mo ago

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

Laravel Response
================

[](#laravel-response)

A lightweight Laravel package that provides a clean, consistent structure for API success and error responses. Supports **Laravel 8 → 12** with auto-discovery.

---

 [![](https://camo.githubusercontent.com/3df390cb252372b7b39cd2540b6928d9acd2c0e61ae4938dfa40f7bb80af20b0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666164797265646139392f6c61726176656c2d726573706f6e73653f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/3df390cb252372b7b39cd2540b6928d9acd2c0e61ae4938dfa40f7bb80af20b0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666164797265646139392f6c61726176656c2d726573706f6e73653f7374796c653d666f722d7468652d6261646765) [![](https://camo.githubusercontent.com/98a2b8d7a94fbe5a847f0d6a1f53b3671166e652f445e2b4f6e4599f28a433d9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666164797265646139392f6c61726176656c2d726573706f6e73653f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/98a2b8d7a94fbe5a847f0d6a1f53b3671166e652f445e2b4f6e4599f28a433d9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666164797265646139392f6c61726176656c2d726573706f6e73653f7374796c653d666f722d7468652d6261646765) [![](https://camo.githubusercontent.com/e4cde31c800abf1e346c6e2fa9d3d02b069658ee0bcd00415b91296bc56c0232/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d382532307c253230392532307c25323031302532307c25323031312532307c25323031322d7265643f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/e4cde31c800abf1e346c6e2fa9d3d02b069658ee0bcd00415b91296bc56c0232/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d382532307c253230392532307c25323031302532307c25323031312532307c25323031322d7265643f7374796c653d666f722d7468652d6261646765) [![](https://camo.githubusercontent.com/daa52099573be5a50c320c4387496400f2f722e49f86a42db8d5778130d3582d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e3f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/daa52099573be5a50c320c4387496400f2f722e49f86a42db8d5778130d3582d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e3f7374796c653d666f722d7468652d6261646765)

---

🚀 Introduction
--------------

[](#-introduction)

Every Laravel project needs a unified structure for API responses. This package solves that by providing:

- `successResponse()` → Standard success JSON
- `errorResponse()` → Standard error JSON
- Optional `BaseController` → Automatically includes the trait
- Clean, readable, reusable responses across all your apps

---

📦 Installation
--------------

[](#-installation)

```
composer require fadyreda99/laravel-response
```

Laravel auto-discovers the package — **no configuration needed.**

---

🧩 Usage
-------

[](#-usage)

### Import and use the trait:

[](#import-and-use-the-trait)

```
use Fadyreda99\LaravelResponse\ResponseTrait;

class UserController extends Controller
{
    use ResponseTrait;

    ### basic example to return success response
    public function successIndex()
    {
        return $this->successResponse(
            ['users' => User::all()],
            'Users fetched successfully'
        );
    }

     ###  example to return success response with pagination data
    public function successIndex()
    {
        $users = Uset::paginate(10);
        $userResource = UserResource::collection($users);
        // get pagination data
        $paginationData = $this->getPaginationData($users);
        return $this->successResponse($userResource, 'ok', 201, $paginationData);
    }

    ### basic example to return error response
    public function errorIndex()
    {
        return $this->errorResponse(
            'Invalid request',
            400
        );
    }
}
```

---

📘 Full Examples (Everything You Need)
=====================================

[](#-full-examples-everything-you-need)

---

✅ 1. Success Response
---------------------

[](#-1-success-response)

### 🔹 Basic Example

[](#-basic-example)

```
return $this->successResponse(
    ['id' => 1, 'name' => 'Fady'],
    'User loaded successfully'
);
```

**Response JSON:**

```
{
  "status": "success",
  "message": "User loaded successfully",
  "data": {
    "id": 1,
    "name": "Fady"
  }
}
```

---

### 🔹 With basic Pagination

[](#-with-basic-pagination)

```
return $this->successResponse(
    $users,
    'Users retrieved',
    200,
    [
        'page' => 1,
        'per_page' => 10,
        'total' => 100
    ]
);
```

**Response JSON:**

```
{
    "status": "success",
    "message": "Users retrieved",
    "data": [...],
    "pagination": {
        "page": 1,
        "per_page": 10,
        "total": 100
    }
}
```

---

### 🔹 With Pagination from package

[](#-with-pagination-from-package)

```
  $paginationData = $this->getPaginationData($users);
  return $this->successResponse(
    $userResource,
     'ok',
     200,
     $paginationData
    );
```

**Response JSON:**

```
{
    "status": "success",
    "message": "Users retrieved",
    "data": [...],
    "pagination": {
        "current_page": 1,
        "last_page": 5,
        "total_page": 5,
        "per_page": 2,
        "total_items": 10,
        "from": 1,
        "to": 2,
        "next_page_url": "URL/test?page=2",
        "prev_page_url": null,
        "first_page_url": "URL/test?page=1",
        "last_page_url": "URL/test?page=5",
        "path": "URL/test"
    }
}
```

---

### 🔹 With Additional Data

[](#-with-additional-data)

```
return $this->successResponse(
    $users,
    'Users retrieved',
    200,
    ['page' => 1],
    ['debug' => 'Extra info here']
);
```

**Response JSON:**

```
{
    "status": "success",
    "message": "Users retrieved",
    "data": [...],
    "pagination": { "page": 1 },
    "additionals": { "debug": "Extra info here" }
}
```

---

❌ 2. Error Response
-------------------

[](#-2-error-response)

### 🔹 Basic Error Example

[](#-basic-error-example)

```
return $this->errorResponse(
    'Invalid request',
    400
);
```

**Response JSON:**

```
{
  "status": "error",
  "message": "Invalid request"
}
```

---

### 🔹 Error With Additional Data

[](#-error-with-additional-data)

```
return $this->errorResponse(
    'Validation failed',
    422,
    ['email' => 'Email is required']
);
```

**Response JSON:**

```
{
  "status": "error",
  "message": "Validation failed",
  "data": {
    "email": "Email is required"
  }
}
```

📝 License
=========

[](#-license)

This package is open-sourced under the **MIT License**.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance72

Regular maintenance activity

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

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

Every ~0 days

Total

5

Last Release

161d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8a531d35d2b3f9c22fac568e8955acb2b8f7933bce328e7f63139cad3a7288b5?d=identicon)[fadyreda99](/maintainers/fadyreda99)

---

Top Contributors

[![fadyreda99](https://avatars.githubusercontent.com/u/130838390?v=4)](https://github.com/fadyreda99 "fadyreda99 (14 commits)")

### Embed Badge

![Health badge](/badges/fadyreda99-laravel-response/health.svg)

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

###  Alternatives

[watson/active

Laravel helper for recognising the current route, controller and action

3253.6M14](/packages/watson-active)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[beyondcode/laravel-favicon

Create dynamic favicons based on your environment settings.

37345.5k](/packages/beyondcode-laravel-favicon)[glhd/conveyor-belt

14797.0k](/packages/glhd-conveyor-belt)[dragon-code/pretty-routes

Pretty Routes for Laravel

10058.7k4](/packages/dragon-code-pretty-routes)[erlandmuchasaj/laravel-gzip

Gzip your responses.

40129.3k2](/packages/erlandmuchasaj-laravel-gzip)

PHPackages © 2026

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