SQLSTATE [42S02]:找不到基表或视图:1146表X不存在

SQLSTATE [42S02]:找不到基表或视图:1146表X不存在

问题描述:

我在Laravel 5中遇到此错误:

I am getting this error in Laravel 5:

SQLSTATE [42S02]:找不到基表或视图:1146表'intern.users'不存在(SQL:从*用户名=管理员限制1的用户中选择*)

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'intern.users' doesn't exist (SQL: select * from users where username = admin limit 1)

config/database.php

config/database.php

        'mysql' => [
    'driver'    => 'mysql',
    'host'      => 'localhost',
    'database'  => 'intern',
    'username'  => 'root',
    'password'  => '',
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
    'strict'    => false,
],

该函数admin被称为admin页面,并且其中提到数据库表是因为admin,因为其中有很多表.

The function admin is called for admin page, and database table is mentioned in it as admin because there are many tables in it.

    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');
    }


        }   



       }    

表格在这里:

  <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() !!}

首先,您应哈希并创建用户"详细信息以使该列准备好进行身份验证.

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.

步骤1:获取输入

$UserData = Input::all();

第2步::创建条目-插入用户表

Step 2 : Create the entry - Inserting into User Table

User::create($UserData);

注意:

您应该在users表中包含以下几句

You should have these following coloumns in your users table

  1. 电子邮件,
  2. 密码
  3. created_at
  4. updated_at

其他设置:

在您的User.php(模型)中有此行

Have this line in your User.php (Model)

protected $fillable = ['email', 'password'];

这是我的小登录代码,对您来说足够简单

如有需要,请尝试一下

$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
}

推荐:

我还建议在创建之前先验证用户输入

I would also recommend to validate the user input before creating

附加说明:

如果您看到表格,并且密码像加密的一样,则表示您已经完成;)

If you see your table and if you password is something like encrypted and it means that you're done ;)