Configure more than one auth driver #834
-
Is there is a way to use more than one auth driver I have two guards company and employee and want to store activities for both 'default_auth_driver' =>[ 'company', 'employee'], trying to do this but not working |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
@freekmurze what's the reason for this config value? @9khaledSayed there's currently no way to use multiple guards directly. The only way I could imagine would be to don't do a single activity log before auth, call |
Beta Was this translation helpful? Give feedback.
-
Hey @9khaledSayed , app/ActivityLog/ActivityLogger.php <?php
namespace App\ActivityLog;
use Illuminate\Auth\AuthManager;
use Illuminate\Contracts\Config\Repository as Config;
use Spatie\Activitylog\ActivityLogger as SpatieActivityLogger;
use Spatie\Activitylog\ActivityLogStatus;
class ActivityLogger extends SpatieActivityLogger;
{
public function __construct(AuthManager $auth, Config $config, ActivityLogStatus $logStatus)
{
parent::__construct($auth, $config, $logStatus);
$this->authDriver = $auth->guard('company')->check() ? 'company' : 'employee'; // this can be customized to any logic you want/need
}
} app/Providers/AppServiceProvider.php use Spatie\Activitylog\ActivityLogger as SpatieActivityLogger;
use App\ActivityLog\ActivityLogger;
// ...
public function register(): void
{
// ...
$this->app->bind(SpatieActivityLogger::class, ActivityLogger::class);
// ...
}
// ... |
Beta Was this translation helpful? Give feedback.
Hey @9khaledSayed ,
so we can solve this discussion I will post these snippets as a "real" answer as the comments can't be flagged as accepted answer.
If you use these snippets everything should work. The first is the whole file the second is one line you have to copy in the surrounding method. 😉
app/ActivityLog/ActivityLogger.php