Skip to content

Instantly share code, notes, and snippets.

@mohitmamoria
Last active August 29, 2015 14:02
Show Gist options
  • Save mohitmamoria/d9ba64f48996e9393d28 to your computer and use it in GitHub Desktop.
Save mohitmamoria/d9ba64f48996e9393d28 to your computer and use it in GitHub Desktop.
Extending Auth in a Service Provider
<?php
// I am trying to extend Auth using a custom driver for MongoDB in the package's service provider's register method:
$this->app['auth']->extend('mongo', function($app)
{
return new Auth\MongoUserProvider($app['db']->connection('mongo'), $app['config']['auth.table']);
});
// But getting error that "Class auth does not exist in Container at line 485.". I tried doing this:
dd($this->app['auth']);
// But got the error again. I am sensing that the 'auth' is not bound yet to the app in the service provider.
// However, if I do the following in global.php file, it works just fine.
Auth::extend(...);
// Anything special about Auth component that doesn't allow it to extend in service provider?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment