Skip to content

Commit 429262a

Browse files
committed
Don't crash with non-standard auth configs
Fixes #527
1 parent e24dce0 commit 429262a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/BouncerServiceProvider.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Support\ServiceProvider;
1111
use Illuminate\Contracts\Auth\Access\Gate;
1212
use Illuminate\Database\Eloquent\Relations\Relation;
13+
use Illuminate\Database\Eloquent\Model as EloquentModel;
1314

1415
class BouncerServiceProvider extends ServiceProvider
1516
{
@@ -118,13 +119,15 @@ protected function publishMigrations()
118119
*/
119120
protected function setUserModel()
120121
{
121-
Models::setUsersModel($this->getUserModel());
122+
if ($model = $this->getUserModel()) {
123+
Models::setUsersModel($model);
124+
}
122125
}
123126

124127
/**
125128
* Get the user model from the application's auth config.
126129
*
127-
* @return string
130+
* @return string|null
128131
*/
129132
protected function getUserModel()
130133
{
@@ -138,7 +141,14 @@ protected function getUserModel()
138141
return null;
139142
}
140143

141-
return $config->get("auth.providers.{$provider}.model");
144+
$model = $config->get("auth.providers.{$provider}.model");
145+
146+
// The standard auth config that ships with Laravel references the
147+
// Eloquent User model in the above config path. However, users
148+
// are free to reference anything there - so we check first.
149+
if (is_subclass_of($model, EloquentModel::class)) {
150+
return $model;
151+
}
142152
}
143153

144154
/**

0 commit comments

Comments
 (0)