Skip to content

Instantly share code, notes, and snippets.

@adampatterson
Created October 11, 2016 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adampatterson/aa20e9829e63e95fd19fb1b24faddc51 to your computer and use it in GitHub Desktop.
Save adampatterson/aa20e9829e63e95fd19fb1b24faddc51 to your computer and use it in GitHub Desktop.
Laravel controllers with
<?
/*
I am using route caching that prevents me from using closures, but even then I don't see why I can't choose to pass static information to a controller without using route parameters.
For example, My project has an umber of redirects in it, and rather than loading up 40 domains with redirect DNS entries that only I have access to.
I have a helper controller to do this so that my team may make entries.
I am running 40 unique sites out of one Laravel instance to keep my maintenance low. 40 sites x about 25 redirects is a lot of DNS entries.
*/
// What I want
Route::get('wrong/url', 'RedirectController@redirect')->with(['path'=>'new/path']);
Route::get('another/wrong/url', 'RedirectController@redirect')->with(['path'=>'another/new/path']);
public function redirect($path)
{
return redirect($path, 301);
}
// What I have now
Route::get('wrong/url', 'RedirectController@redirectWrongUrl');
Route::get('another/wrong/url', 'RedirectController@redirectAnotherWrongUrl');
public function redirectWrongUrl()
{
return redirect('new/path', 301);
}
public function redirectAnotherWrongUrl()
{
return redirect('another/new/path', 301);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment