Skip to content

Instantly share code, notes, and snippets.

@aranw
Last active December 26, 2015 18:19
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 aranw/7193744 to your computer and use it in GitHub Desktop.
Save aranw/7193744 to your computer and use it in GitHub Desktop.
<?php
//Needs refactoring I guess into one, but thats a topic for another day
Route::filter('user', function() {
if (! Session::has('User')) {
return Redirect::to('/');
}
});
Route::filter('guest', function() {
if (Session::has('User')) {
return Redirect::to('/');
}
});
So, as you can see I have too routes for "/". Because the filters are redirecting, it causes a redirect loop!
I didn't really want just one route, and then point it to function like this:
function homeDelegate() {
if($this->is_user) {
return $this->dashboard();
}
return $this->homepage();
}
...and then have the seperate functions there. At the moment, I'm either using filters wrongly (clearly I am, but I mean more ethically) or I'm going to have to use the delegate func above. Any tips? Ideas? Cool Laravel stuff?
<?php
/*
|--------------------------------------------------------------------------
| Home Controller Routes
|--------------------------------------------------------------------------
|
| Defined routes for the Home Controller. This just handles our users
| dashboard (homepage).
|
*/
Route::group(['before' => 'guest'], function()
{
Route::get('/', ['as' => 'dashboard', 'uses' => 'ET\Controller\HomeController@homepage']);
});
Route::group(['before' => 'user'], function()
{
Route::get('/', ['as' => 'dashboard', 'uses' => 'ET\Controller\HomeController@homepage']);
});
Route::any('/', [
'before' => 'guest',
'as' => 'dashboard',
'uses' => 'ET\Controller\HomeController@homepage'
]);
Route::any('/', [
'before' => 'user',
'as' => 'dashboard',
'uses' => 'ET\Controller\HomeController@dashboard'
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment