Skip to content

Instantly share code, notes, and snippets.

@calebporzio
Created April 19, 2017 21:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save calebporzio/a7b3fc29807226e8d1d665c49a560816 to your computer and use it in GitHub Desktop.
Save calebporzio/a7b3fc29807226e8d1d665c49a560816 to your computer and use it in GitHub Desktop.
<?php
// Until SessionGuard Macros get pulled into Laravel core from a PR:
// Remove this when Laravel 5.4.18 is released.
$this->app->config->set('auth.guards.hack', [
'driver' => 'modified-session',
'provider' => 'users',
]);
Auth::extend('modified-session', function ($app, $name, $config) {
// The following is taken from AuthManager@createSessionDriver
$provider = Auth::createUserProvider($config['provider']);
$guard = new class ($name, $provider, $app['session.store']) extends SessionGuard {
// This allows Auth::macro(...)
use Macroable;
};
if (method_exists($guard, 'setCookieJar')) {
$guard->setCookieJar($app['cookie']);
}
if (method_exists($guard, 'setDispatcher')) {
$guard->setDispatcher($app['events']);
}
if (method_exists($guard, 'setRequest')) {
$guard->setRequest($app->refresh('request', $guard, 'setRequest'));
}
return $guard;
});
Auth::shouldUse('hack');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment