laravel SQLSTATE[42S02]:未找到基表或视图:1146 表 X 不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31233896/
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
SQLSTATE[42S02]: Base table or view not found: 1146 Table X doesn't exist
提问by deep singh
I am getting this error in Laravel 5:
我在 Laravel 5 中收到此错误:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'intern.users' doesn't exist (SQL: select * from users where username = admin limit 1)
SQLSTATE[42S02]:未找到基表或视图:1146 表“intern.users”不存在(SQL:从用户名中选择 * 用户名 = 管理员限制 1)
config/database.php
配置/数据库.php
'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'intern',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
The function admin is called for admin page, and database table is mentioned in it as admin because there are many tables in it.
admin页面调用函数admin,其中数据库表被称为admin,因为里面有很多表。
public function admin(Request $request){
if($request->isMethod('get')){
return \View::make('student.admin');
} else
{
$check=0;
$check=\DB::table('admin')->get();
$username = Input::get('username');
$password = Input::get('password');
$data=array(
'username'=>$request->get('username'),
'password'=>$request->get('password')
);
if(\Auth::attempt($data))
{
return redirect::intended('student/index');
}
else
{
return redirect('student/admin');
}
}
}
Form is here:
表格在这里:
<div id="pageContent"><br />
<div align="left" style="margin-left:24px;">
<h2>Please Log In To Manage</h2>
{!! Form::open(array('url' => '/admin')) !!}
<input type="hidden" name="_token" value="{{ csrf_token() }}">
User Name:<br />
<input name="username" type="text" id="username" size="40" />
<br /><br />
Password:<br />
<input name="password" type="password" id="password" size="40" />
<br />
<br />
<br />
<input type="submit" name="button" id="button" value="Log In" />
{!! Form::close() !!}
采纳答案by Sulthan Allaudeen
First you should hash and create the User details to make the coloumn ready for authentication.
首先,您应该散列并创建用户详细信息,以使该列准备好进行身份验证。
Here i have given the steps to achieve it.
在这里,我已经给出了实现它的步骤。
Step 1 :Get the Input
第 1 步:获取输入
$UserData = Input::all();
$UserData = Input::all();
Step 2 :Create the entry - Inserting into User Table
第 2 步:创建条目 - 插入用户表
User::create($UserData);
User::create($UserData);
Note :
笔记 :
You should have these following coloumns in your users
table
您的users
表格中应该有以下这些列
- email,
- password
- created_at
- updated_at
- 电子邮件,
- 密码
- created_at
- 更新时间
Additional Setup :
附加设置:
Have this line in your User.php (Model)
在您的 User.php(模型)中有这一行
protected $fillable = ['email', 'password'];
Here's my tiny login code for you which would simple enough for you
这是我给你的小登录代码,对你来说足够简单
Have a try over this if you wish
如果你愿意,可以试试这个
$email = $this->request->input('email');
$password = $this->request->input('password');
if (Auth::attempt(['email' => $email, 'password' => $password])) #If the Credentials are Right
{
return redirect::intended('student/index'); #Your Success Page
}
else
{
return redirect('student/admin'); #Your Failure Page
}
Recommendation :
推荐 :
I would also recommend to validatethe user input before creating
我还建议在创建之前验证用户输入
Additional Note :
附加说明:
If you see your table and if you password is something like encrypted and it means that you're done ;)
如果你看到你的桌子,如果你的密码是加密的,那就意味着你已经完成了;)