Skip to content

Commit

Permalink
Don't crash with non-standard auth configs
Browse files Browse the repository at this point in the history
Fixes #527
  • Loading branch information
JosephSilber committed Dec 8, 2020
1 parent e24dce0 commit 429262a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/BouncerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Auth\Access\Gate;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\Model as EloquentModel;

class BouncerServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -118,13 +119,15 @@ protected function publishMigrations()
*/
protected function setUserModel()
{
Models::setUsersModel($this->getUserModel());
if ($model = $this->getUserModel()) {
Models::setUsersModel($model);
}
}

/**
* Get the user model from the application's auth config.
*
* @return string
* @return string|null
*/
protected function getUserModel()
{
Expand All @@ -138,7 +141,14 @@ protected function getUserModel()
return null;
}

return $config->get("auth.providers.{$provider}.model");
$model = $config->get("auth.providers.{$provider}.model");

// The standard auth config that ships with Laravel references the
// Eloquent User model in the above config path. However, users
// are free to reference anything there - so we check first.
if (is_subclass_of($model, EloquentModel::class)) {
return $model;
}
}

/**
Expand Down

0 comments on commit 429262a

Please sign in to comment.