Skip to content

Commit 3cdf7d3

Browse files
committed
Consult App's Auth Config For User Model
Laravel includes a configuration option in `app/config/auth.php` to specify which model to use to represent users. It should be consulted first, before falling back on convention to determine the model name. (Also removed extraneous namespace characters.)
1 parent 69de732 commit 3cdf7d3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/Helpers/User.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php namespace Taskforcedev\LaravelSupport\Helpers;
22

3-
use \Auth;
3+
use Auth;
4+
use Config;
45
use Illuminate\Console\AppNamespaceDetectorTrait;
56

67
class User
@@ -13,7 +14,12 @@ class User
1314
*/
1415
public function getUserModel()
1516
{
16-
/* Get the namespace */
17+
/* Check the app's auth config, first */
18+
$model = Config::get('auth.model');
19+
if (class_exists($model)) {
20+
return $model;
21+
}
22+
/* That didn't work, so let's try our fallback. First get the namespace */
1723
$ns = $this->getAppNamespace();
1824
if ($ns) {
1925
/* Try laravel default convention (models in the app folder). */
@@ -36,7 +42,7 @@ public function getUserModel()
3642
*/
3743
public function getUser()
3844
{
39-
return (Auth::check() ? \Auth::user() : $this->createGuest());
45+
return (Auth::check() ? Auth::user() : $this->createGuest());
4046
}
4147

4248
/**

0 commit comments

Comments
 (0)