简体   繁体   中英

add custom method on redirect() helper in laravel

I want to add custom method on redirect() helper such as it:

redirect()->custom(...$params)

Do it posibble?

You can macro a custom method on the Redirector class if you would like. In a Service Provider's boot method you can define your macro:

use Illuminate\Routing\Redirector;

public function boot()
{
    Redirector::macro('custom', function ($your, $arguments, $here) {
        ...
    });
}

Then you could access it the way you would like:

redirect()->custom(...);

The Redirector has been macroable since version 5.5.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM