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

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

f9webltd/laravel-redirect-response-macros
=========================================

Some useful redirect response macros for your Laravel application

3.0.0(2mo ago)212.3k↑450%MITPHPPHP ^8.2CI passing

Since Aug 15Pushed 2mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (6)Versions (19)Used By (0)

[![](https://camo.githubusercontent.com/6672b3de7d26ee6fb1e8b038c61c6da680004078467f31153bf9c53277075609/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c2532305265646972656374253230526573706f6e73652532304d6163726f732e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d66397765626c74642532466c61726176656c2d72656469726563742d726573706f6e73652d6d6163726f73267061747465726e3d627269636b57616c6c267374796c653d7374796c655f31266465736372697074696f6e3d536f6d652b73757065722b75736566756c2b72656469726563742b726573706f6e73652b6d6163726f732b746f2b73696d706c6966792b796f75722b4c61726176656c2b6170706c69636174696f6e266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d636f6465)](https://camo.githubusercontent.com/6672b3de7d26ee6fb1e8b038c61c6da680004078467f31153bf9c53277075609/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c2532305265646972656374253230526573706f6e73652532304d6163726f732e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d66397765626c74642532466c61726176656c2d72656469726563742d726573706f6e73652d6d6163726f73267061747465726e3d627269636b57616c6c267374796c653d7374796c655f31266465736372697074696f6e3d536f6d652b73757065722b75736566756c2b72656469726563742b726573706f6e73652b6d6163726f732b746f2b73696d706c6966792b796f75722b4c61726176656c2b6170706c69636174696f6e266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d636f6465)

![PHP ^8.2](https://camo.githubusercontent.com/fa17bda6467c1bb0eb1e951a14530c78330a9fb1cfa87b1918c1e33522fdb812/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e322d627269676874677265656e)[![Packagist Version](https://camo.githubusercontent.com/ab099458b7448b47924231bdd5c5efd92761b6655317b27b12c76742e32e7d29/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f66397765626c74642f6c61726176656c2d72656469726563742d726573706f6e73652d6d6163726f733f7374796c653d666c61742d737175617265)](https://packagist.org/packages/f9webltd/laravel-redirect-response-macros)[![Run Tests](https://github.com/f9webltd/laravel-redirect-response-macros/actions/workflows/run-tests.yml/badge.svg?branch=master)](https://github.com/f9webltd/laravel-redirect-response-macros/actions/workflows/run-tests.yml)[![StyleCI Status](https://camo.githubusercontent.com/b6bf9e30f2ffee82d7e1e0c640da818dc34b72844fd3e7b1876a7c6cb741a241/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3237383538313331382f736869656c64)](https://github.styleci.io/repos/278581318)[![Packagist License](https://camo.githubusercontent.com/10173eb83081e31a8686f2cb90fd9520e440b9b43d9f3bc412717991bdc059a0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f66397765626c74642f6c61726176656c2d72656469726563742d726573706f6e73652d6d6163726f733f7374796c653d666c61742d737175617265)](https://packagist.org/packages/f9webltd/laravel-redirect-response-macros)

Laravel Redirect Response Macros
================================

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

Some super useful redirect response macros to simplify your Laravel application.

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

[](#requirements)

- PHP `^8.2`
- Laravel `^11.0` / `^12.0` / `^13.0`

The package supports actively supported Laravel releases as per the official [Laravel Support Policy](https://laravel.com/docs/master/releases#support-policy).

### Legacy Support

[](#legacy-support)

For legacy PHP / Laravel support, use package version [`2.1.0`](https://github.com/f9webltd/laravel-redirect-response-macros/tree/2.1.0)

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

[](#installation)

```
composer require f9webltd/laravel-redirect-response-macros
```

The package will automatically register itself.

Optionally publish language files by running: `php artisan vendor:publish` and selecting the appropriate package.

Documentation
-------------

[](#documentation)

This package allows for concise controller redirections by setting default flash data. It works as Laravels `RedirectResponse` class is "macroable".

For example the packages allows:

```
public function store(FormRequest $request)
{
    // create record ...
    return redirect()->route('posts.index')->created();
}
```

... instead of:

```
public function store(FormRequest $request)
{
    // create record ...
    return redirect()->route('posts.index')->with('success', 'The record was successfully created');
}
```

The former is of course much more concise and readable.

The package specifies several custom `RedirectResponse` macros that can be used on any of the native Laravel helpers that return the redirect response object.

The following methods are available.

#### `success()`

[](#success)

Flash message key: `success`
Pass a message string to the macros.

```
public function update(FormRequest $request, $id)
{
    return back()->success('Everything is great!');
}
```

#### `info()`

[](#info)

Flash message key: `info`
Pass a message string to the macros.

```
public function update(FormRequest $request, $id)
{
    return back()->info('Some information ...');
}
```

#### `danger()`

[](#danger)

Flash message key: `danger`
Pass a message string to the macros.

```
public function update(FormRequest $request, $id)
{
    return back()->danger('That action just is impossible!');
}
```

#### `warning()`

[](#warning)

Flash message key: `warning`
Pass a message string to the macros.

```
public function update(FormRequest $request, $id)
{
    return back()->warning('This could be risky ...');
}
```

There are further helper method available, that set the same type of flash data, but in a more readable manner:

#### `created()`

[](#created)

Flash message key: `success`
Default message: `The record was successfully created`

```
public function store(FormRequest $request)
{
    // create record ...
    return redirect()->route('posts.index')->created();
}
```

Alternatively pass a url to display an message with a link to view the created record:

```
public function store(FormRequest $request)
{
    // create record ...
    return redirect()->route('posts.index')->created(
      route('posts.edit', $post)
    );
}
```

The flashed message will now be: `The record was successfully created. View inserted record`.

#### `updated()`

[](#updated)

Flash message key: `success`
Default message: `The record was successfully updated`

```
public function update(FormRequest $requestm int $id)
{
    // update record ...
    return back()->updated();
}
```

To set a custom message, pass the desired text to the `updated()` function.

#### `deleted()`

[](#deleted)

Flash message key: `success`
Default message: `The record was successfully deleted`

```
public function update(Post $post)
{
    $posts->delete();

    return redirect()->route('posts.index')->deleted();
}
```

To set a custom message, pass the desired text to the `deleted()` function.

#### `error()`

[](#error)

Flash message key: `error`
Specific message text should be passed.

```
public function index()
{
    // code ...
    return redirect()->route('dashboard')->error('You cannot do this thing!');
}
```

The function can detect the presence of exception object and call `getMessage()` as required:

```
public function index()
{
    try {
        $service->run();
    } catch (Exception $e) {
        return redirect()->route('dashboard')->error($e)
    }
}
```

#### `errorNotFound()`

[](#errornotfound)

Works in the same way as the `error()` macro and is intended to make controllers more concise.

The default message is `Sorry, the record could not be found.`.

#### `authorized()`

[](#authorized)

Flash message key: `success`
Default message: `Welcome back, you have been securely logged in`

A custom message can optionally be provided.

#### `unAuthorized()`

[](#unauthorized)

Works in the same way as the `error()` macro and is intended to make controllers more concise.

The default message is `You do not have permission to perform that action`.

IDE Autocompletion within PHPStorm
----------------------------------

[](#ide-autocompletion-within-phpstorm)

Autocompletion of "macroable" classes with PHPStorm currently difficult, which is a shame given how useful macroable classes actually are.

At present, the following process will trigger autocompletion in PHPStorm:

- Copy [resources/\_ide\_helper\_macros.php](resources/_ide_helper_macros.php) to a location within your project to allow PHP storm to index the additional class methods
- Optionally add `_ide_helper_macros.php` to your `.gitignore` file

Contribution
------------

[](#contribution)

Any ideas are welcome. Feel free to submit any issues or pull requests.

Testing
-------

[](#testing)

```
composer test
```

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Rob Allport](https://github.com/ultrono) for [F9 Web Ltd.](https://www.f9web.co.uk)
- [All Contributors](https://github.com/f9webltd/laravel-response-macros/graphs/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance87

Actively maintained with recent releases

Popularity29

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity76

Established project with proven stability

 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 ~203 days

Recently: every ~370 days

Total

11

Last Release

65d ago

Major Versions

1.1.6 → 2.0.02024-03-12

2.1.0 → 3.0.02026-03-08

PHP version history (4 changes)1.0.0PHP ^7.2

1.1.3PHP ^7.2|^8.0

2.0.0PHP ^8.0

3.0.0PHP ^8.2

### Community

Maintainers

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

---

Top Contributors

[![ultrono](https://avatars.githubusercontent.com/u/1782734?v=4)](https://github.com/ultrono "ultrono (12 commits)")

---

Tags

laravellaravel-frameworklaravel-macroslaravel-redirectlaravel-redirect-responselaravel-redirectslaravellaravel-redirectredirect response macroslaravel macros

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/f9webltd-laravel-redirect-response-macros/health.svg)

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)[nedwors/navigator

A Laravel package to ease defining navigation menus

433.1k](/packages/nedwors-navigator)[xefi/faker-php-laravel

Faker php integration with laravel

1915.1k](/packages/xefi-faker-php-laravel)[dcblogdev/laravel-junie

Install pre-configured guides for Jetbrains Junie

392.5k](/packages/dcblogdev-laravel-junie)

PHPackages © 2026

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