Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php laravel,获取Auth::user()表名_Php_Authentication_Laravel 5 - Fatal编程技术网

Php laravel,获取Auth::user()表名

Php laravel,获取Auth::user()表名,php,authentication,laravel-5,Php,Authentication,Laravel 5,laravel版本:5.0 我目前正在laravel中制作管理员登录中间件 即时通讯使用laravel默认身份验证的开箱即用。 在此状态下,我已成功登录 据我所知,我可以通过执行Auth::user()->id,, 但问题是:我找不到检索表名的方法 下面是执行dd(Auth::User())时的结果 如您所见,它包含信息#表:“管理员” 这是我的中间件,我想在其中检查表名是否为admin: <?php namespace App\Http\Middleware; use Closure;

laravel版本:5.0

我目前正在laravel中制作管理员登录中间件

即时通讯使用laravel默认身份验证的开箱即用。 在此状态下,我已成功登录

据我所知,我可以通过执行
Auth::user()->id,,
但问题是:我找不到检索表名的方法

下面是执行
dd(Auth::User())时的结果

如您所见,它包含信息#表:“管理员”


这是我的中间件,我想在其中检查表名是否为admin:

<?php namespace App\Http\Middleware;
use Closure;
use Auth;

class AdminMiddleware extends Model{

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        if(Auth::User()->getTable() == 'admins') //this doesnt work
        {
            return $next($request);
        }
        else
        {
            return response('Unauthorized.', 401);
        }

    }

}

如果您的管理员
正在扩展
雄辩\模型
管理员::getTable()
$adminInstance->getTable())
应该可以工作。

不是为管理员和用户创建两个单独的表,而是将他们的凭据放在同一个表中,并使用第二个表,即roles,其中包含用户角色的详细信息。如果您想要相同的表结构和代码,请告诉我,我将与您分享

谢谢您的回复。对不起,我已经改进了我的问题以了解更多细节。。。你是说我的班级吗?因为我试图从当前授权用户处获取表名,而不是从我的数据库获取。为什么要获取表名?我有用户表和管理员表,我试图验证登录凭据是否为管理员,我是否缺少某些内容。。?这种方法看起来很肮脏
<?php namespace App\Http\Middleware;
use Closure;
use Auth;

class AdminMiddleware extends Model{

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        if(Auth::User()->getTable() == 'admins') //this doesnt work
        {
            return $next($request);
        }
        else
        {
            return response('Unauthorized.', 401);
        }

    }

}