PHPackages                             myerscode/laravel-sub-request - 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. myerscode/laravel-sub-request

ActivePackage[API Development](/categories/api)

myerscode/laravel-sub-request
=============================

A helper and facade for making internal API sub requests to your application

13.0.0(3mo ago)746.1k↓54.2%[1 PRs](https://github.com/myerscode/laravel-sub-request/pulls)MITPHPPHP ^8.3CI passing

Since Oct 5Pushed 1w ago1 watchersCompare

[ Source](https://github.com/myerscode/laravel-sub-request)[ Packagist](https://packagist.org/packages/myerscode/laravel-sub-request)[ Docs](https://github.com/myerscode/laravel-sub-request)[ RSS](/packages/myerscode-laravel-sub-request/feed)WikiDiscussions main Synced yesterday

READMEChangelog (1)Dependencies (11)Versions (16)Used By (0)

Laravel Sub Request
===================

[](#laravel-sub-request)

A helper and facade for making internal sub requests to your application API.

[![Latest Stable Version](https://camo.githubusercontent.com/1cdcd2cf9cab48fcd00fca71851156db06acf0022e29fdbed337dada4e1739f0/68747470733a2f2f706f7365722e707567782e6f72672f6d79657273636f64652f6c61726176656c2d7375622d726571756573742f762f737461626c65)](https://packagist.org/packages/myerscode/laravel-sub-request)[![Total Downloads](https://camo.githubusercontent.com/accb53039d39d9dae501504800c02e8e693860e631b8b04c9424865fd609f54d/68747470733a2f2f706f7365722e707567782e6f72672f6d79657273636f64652f6c61726176656c2d7375622d726571756573742f646f776e6c6f616473)](https://packagist.org/packages/myerscode/laravel-sub-request)[![PHP Version Require](https://camo.githubusercontent.com/c4b644611a915e514879412487157849ba76e8203fc203103bf5a6cbb844f6c9/687474703a2f2f706f7365722e707567782e6f72672f6d79657273636f64652f6c61726176656c2d7375622d726571756573742f726571756972652f706870)](https://packagist.org/packages/myerscode/laravel-sub-request)[![License](https://camo.githubusercontent.com/5c05817909a78e1e2c301532b4e01552460be32b6864587bd94b33b32097518c/68747470733a2f2f706f7365722e707567782e6f72672f6d79657273636f64652f6c61726176656c2d7375622d726571756573742f6c6963656e7365)](https://github.com/myerscode/laravel-sub-request/blob/main/LICENSE)[![Tests](https://github.com/myerscode/laravel-sub-request/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/myerscode/laravel-sub-request/actions/workflows/tests.yml)[![codecov](https://camo.githubusercontent.com/652f10d1933aadd6cf04aa7771795fc3455803d2649dcb5aa95168917880c2b0/68747470733a2f2f636f6465636f762e696f2f67682f6d79657273636f64652f6c61726176656c2d7375622d726571756573742f67726170682f62616467652e737667)](https://codecov.io/gh/myerscode/laravel-sub-request)

By sending a sub request within the application, you can consume your application's API without sending separate, slower HTTP requests.

Requirements
------------

[](#requirements)

- PHP 8.5+
- Laravel 13.x

Install
-------

[](#install)

```
composer require myerscode/laravel-sub-request
```

The package will be auto-discovered by Laravel.

Usage
-----

[](#usage)

You can inject the `Dispatcher` into your class, use the `SubRequest` facade, or use the global `subrequest` helper.

```
use Myerscode\Laravel\SubRequest\Dispatcher;
use Myerscode\Laravel\SubRequest\SubRequest;

class MyController
{
    public function __construct(private readonly Dispatcher $subRequest) {}

    // Using dependency injection
    public function withInjection()
    {
        return $this->subRequest->post('/auth', ['foo' => 'bar']);
    }

    // Using the facade
    public function withFacade()
    {
        return SubRequest::dispatch('GET', '/details', ['foo' => 'bar']);
    }

    // Using the helper
    public function withHelper()
    {
        return subrequest('GET', '/details', ['foo' => 'bar']);
    }
}
```

### Available Methods

[](#available-methods)

The `Dispatcher` provides shortcut methods for all HTTP verbs:

```
$dispatcher->get('/url', $data);
$dispatcher->post('/url', $data);
$dispatcher->put('/url', $data);
$dispatcher->patch('/url', $data);
$dispatcher->delete('/url', $data);
$dispatcher->options('/url', $data);
```

### Custom Headers

[](#custom-headers)

All methods accept an optional `$headers` array as the last parameter, allowing you to set custom headers on the sub request:

```
// Set Authorization and Accept headers
$dispatcher->get('/api/users', [], [
    'Authorization' => 'Bearer my-token',
    'Accept' => 'application/json',
]);

// Works with the facade and helper too
SubRequest::dispatch('GET', '/api/users', [], ['Authorization' => 'Bearer my-token']);
subrequest('GET', '/api/users', [], ['Authorization' => 'Bearer my-token']);
```

Headers are applied to the sub request and automatically restored to their original values after dispatch.

### Cookies

[](#cookies)

All methods accept an optional `$cookies` array as the last parameter, allowing you to forward or set cookies on the sub request:

```
// Set cookies on the sub request
$dispatcher->get('/api/profile', [], [], [
    'session_id' => 'abc123',
    'token' => 'my-auth-token',
]);

// Combine headers and cookies
$dispatcher->post('/api/data', ['key' => 'value'], [
    'Accept' => 'application/json',
], [
    'session_id' => 'abc123',
]);

// Works with the facade and helper too
SubRequest::dispatch('GET', '/api/profile', [], [], ['session_id' => 'abc123']);
subrequest('GET', '/api/profile', [], [], ['session_id' => 'abc123']);
```

Cookies are applied to the sub request and automatically restored to their original values after dispatch.

### Middleware Control

[](#middleware-control)

Use `withoutMiddleware()` to skip specific middleware on a sub request:

```
use App\Http\Middleware\Authenticate;
use App\Http\Middleware\RateLimiter;

// Skip a single middleware
$dispatcher->withoutMiddleware(Authenticate::class)->get('/api/internal');

// Skip multiple middleware by chaining
$dispatcher
    ->withoutMiddleware(Authenticate::class)
    ->withoutMiddleware(RateLimiter::class)
    ->post('/api/internal', $data);

// Or pass an array
$dispatcher->withoutMiddleware([Authenticate::class, RateLimiter::class])->get('/api/internal');
```

The middleware exclusion is automatically reset after each dispatch, so subsequent calls will run all middleware as normal.

License
-------

[](#license)

MIT

###  Health Score

59

—

FairBetter than 98% of packages

Maintenance90

Actively maintained with recent releases

Popularity31

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity86

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 90.3% 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 ~515 days

Recently: every ~549 days

Total

7

Last Release

98d ago

Major Versions

1.0.1 → 7.0.02020-03-20

7.0.0 → 8.0.02021-01-07

8.x-dev → 13.0.02026-03-26

PHP version history (5 changes)1.0.0PHP &gt;=7.0

7.0.0PHP ^7.4

8.0.0PHP ^7.3|^8.0

8.0.1PHP ^7.3

13.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/a3d9923c8c4269fbe7076613da7e814719743f643cb115b441ccee8aeaa1290e?d=identicon)[oniice](/maintainers/oniice)

---

Top Contributors

[![oniice](https://avatars.githubusercontent.com/u/2676321?v=4)](https://github.com/oniice "oniice (56 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (6 commits)")

---

Tags

facadehelperlaravelsub-requestlaravelrequestssubsub-request

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/myerscode-laravel-sub-request/health.svg)

```
[![Health](https://phpackages.com/badges/myerscode-laravel-sub-request/health.svg)](https://phpackages.com/packages/myerscode-laravel-sub-request)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

77022.3M150](/packages/laravel-mcp)[nuwave/lighthouse

A framework for serving GraphQL from Laravel

3.5k11.8M117](/packages/nuwave-lighthouse)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.3k3](/packages/defstudio-telegraph)[api-platform/laravel

API Platform support for Laravel

58170.8k14](/packages/api-platform-laravel)[intervention/image-laravel

Laravel Integration of Intervention Image

1588.9M181](/packages/intervention-image-laravel)

PHPackages © 2026

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