Last active
April 8, 2018 02:28
-
-
Save calebporzio/f874da941ff150b6615e5a2e6adc3740 to your computer and use it in GitHub Desktop.
Simple helper macro for a common Laravel controller pattern (redirecting back with status message)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use Illuminate\Support\ServiceProvider; | |
class AppServiceProvider extends ServiceProvider | |
{ | |
public function boot() | |
{ | |
// This is the equivelant of: | |
// "return redirect()->back()->with('message', $message);" | |
\Illuminate\Http\RedirectResponse::macro('message', function ($message) { | |
return $this->with('message', $message); | |
}); | |
// This is the equivelant of: | |
// "return redirect()->back()->with('message', trans($localizationKey));" | |
\Illuminate\Http\RedirectResponse::macro('trans', function ($localizationKey) { | |
return $this->with('message', trans($localizationKey)); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment