Laravel 5 Auth - 带有用户的自定义表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29930646/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5 Auth - custom table with users
提问by ventaquil
I'm learning Laravel auth now and I have small problem. I read some pages from Google about this mechanism and I'm using
我现在正在学习 Laravel 身份验证,但遇到了一些小问题。我从谷歌上阅读了一些关于这个机制的页面,我正在使用
Auth::attempt(['email'=>$request['email'],'password'=>$request['password']]);
Laravel gives me this error:
Laravel 给了我这个错误:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'base.users' doesn't exist (SQL: select * from `users` where `email` = [email protected] limit 1)
In fact I don't have users
table in my database, I'm using name accounts
. How can I change default table in auth?
事实上users
,我的数据库中没有表,我使用的是 name accounts
。如何更改身份验证中的默认表?
And additional question is: when I put data to Auth::attempt() data will changed to SQL query and all data will be get from base? How can I add more data than I get in base? For simple I have table ban
which this field have number of days when ban goes end. And I want to add field isbanned
which get TRUE/FALSE data. If ban
>0 will be TRUE, otherwise FALSE.
另一个问题是:当我将数据放入 Auth::attempt() 时,数据将更改为 SQL 查询并且所有数据都将从基础获取?如何添加比我在基础中获得的数据更多的数据?简单来说,我有一个表格ban
,其中该字段有禁令结束的天数。我想添加isbanned
获取 TRUE/FALSE 数据的字段。如果ban
>0 为 TRUE,否则为 FALSE。
回答by tnash
In config/auth.php
change 'table' => 'users'
to 'table' => 'accounts'
在config/auth.php
更改'table' => 'users'
为'table' => 'accounts'