Skip to content

Instantly share code, notes, and snippets.

@calebporzio
Last active April 8, 2018 02:28
Show Gist options
  • Save calebporzio/f874da941ff150b6615e5a2e6adc3740 to your computer and use it in GitHub Desktop.
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)
<?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