![](/img/trans.png)
[英]SQLSTATE[42S02]: Base table or view not found: 1146 Table '***.indices' doesn't exist laravel
[英]SQLSTATE[42S02]: Base table or view not found: 1146 Table X doesn't exist
我在Laravel 5中收到此錯誤:
SQLSTATE [42S02]:找不到基表或視圖:1146表'intern.users'不存在(SQL:select * from users where username = admin limit 1)
配置/ database.php中
'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'intern',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
管理員頁面調用函數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');
}
}
}
表格在這里:
<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() !!}
首先,您應該散列並創建用戶詳細信息,以使coloumn准備好進行身份驗證。
在這里,我已經給出了實現它的步驟。
第1步:獲取輸入
$UserData = Input::all();
第2步:創建條目 - 插入用戶表
User::create($UserData);
注意 :
您應該在users
表中包含以下coloumns
附加設置:
在User.php(模型)中有這一行
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
}
建議:
我還建議在創建之前驗證用戶輸入
附加說明:
如果你看到你的表,如果密碼是加密的,這意味着你已經完成;)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.