deep singh deep singh - 1 year ago 251
SQL Question

SQLSTATE[42S02]: Base table or view not found: 1146 Table X doesn't exist

I am getting this error in 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)


'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.

public function admin(Request $request){

return \View::make('student.admin');
} else

$username = Input::get('username');
$password = Input::get('password');


return redirect::intended('student/index');
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() !!}

Answer Source

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

$UserData = Input::all();

Step 2 : Create the entry - Inserting into User Table


Note :

You should have these following coloumns in your users table

  1. email,
  2. password
  3. created_at
  4. updated_at

Additional Setup :

Have this line in your User.php (Model)

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
 return redirect('student/admin'); #Your Failure Page

Recommendation :

I would also recommend to validate the 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 ;)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download