Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Replacing the default auth filter with one for multiauth
<?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');
});
@cyborgcassowary

This comment has been minimized.

Copy link

cyborgcassowary commented Dec 19, 2014

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:

Route::filter('auth', function()
{
  if (Auth::admin()->guest())
      {
          if (Request::ajax())
          {
                return Response::make('Unauthorized', 401);
           }
              return Redirect::guest('login');
        }
 });

Screenshot of error I'm receiving: http://imgur.com/no8bjKB

@cyborgcassowary

This comment has been minimized.

Copy link

cyborgcassowary commented Dec 30, 2014

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) "ryan@ryanhettler.com"
   ["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) "ryan@ryanhettler.com"
    ["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
You can’t perform that action at this time.