Created
January 7, 2014 18:00
-
-
Save ollieread/8303638 to your computer and use it in GitHub Desktop.
Replacing the default auth filter with one for multiauth
This file contains hidden or 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 | |
// original auth filter | |
Route::filter('auth', function() | |
{ | |
if (Auth::guest()) return Redirect::guest('login'); | |
}); | |
// new multiauth filter | |
Route::filter('auth', function() | |
{ | |
if (Auth::admin()->guest()) return Redirect::guest('login'); | |
}); |
I figured it out. Did a couple of tests with php artisan tinker
and was successfully able to logout a user with the above code adjustment in filter.php
>var_dump(Auth::user()->loginUsingId(1));
object(Illuminate\Auth\GenericUser)#651 (1) {
["attributes":protected]=>
array(7) {
["id"]=>
string(1) "1"
["username"]=>
string(11) "ryanhettler"
["email"]=>
string(20) "[email protected]"
["password"]=>
string(60) "$2y$10$zVw8.SzNtbM7sqTLmNlqm.OdK72lfESrg2nJdXowjKC8AIKCnkLAK"
["remember_token"]=>
string(60) "n3WyEIKyUURGojCKKGE5QXhThtdluFNpSW6p7kYAb5eP33bCqRfEEuQPomRz"
["created_at"]=>
string(19) "2014-12-18 16:42:09"
["updated_at"]=>
string(19) "2014-12-18 16:42:09"
}
}
>var_dump(Auth::user()->get());
object(Illuminate\Auth\GenericUser)#651 (1) {
["attributes":protected]=>
array(7) {
["id"]=>
string(1) "1"
["username"]=>
string(11) "ryanhettler"
["email"]=>
string(20) "[email protected]"
["password"]=>
string(60) "$2y$10$zVw8.SzNtbM7sqTLmNlqm.OdK72lfESrg2nJdXowjKC8AIKCnkLAK"
["remember_token"]=>
string(60) "n3WyEIKyUURGojCKKGE5QXhThtdluFNpSW6p7kYAb5eP33bCqRfEEuQPomRz"
["created_at"]=>
string(19) "2014-12-18 16:42:09"
["updated_at"]=>
string(19) "2014-12-18 16:42:09"
}
}
>var_dump(Auth::user()->logout());
NULL
>var_dump(Auth::user()->get());
NULL
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm running into some trouble replacing the default filter Auth::guest() with Auth::admin()->guest(). You mention that the default filters no longer works. Is there another way to logout without using Auth::guest()? My code in my filters.php file is below:
Screenshot of error I'm receiving: http://imgur.com/no8bjKB