Laravel – Base table or view not found: 1146 Table

laravel

Error:

Illuminate \ Database \ QueryException (42S02)
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mmictltd.admins' doesn't exist (SQL: select * from admins where email = kayondoronald2015@gmail.com limit 1)

My create_admin_table.php

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateAdminTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('admin', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('admin');
    }
}

Laravel error illustration

Best Answer

Your table's in migration is called 'admin' but in query you are looking for 'admins'.

You can specific table name in your model by $table:

/**
 * The table associated with the model.
 *
 * @var string
 */
protected $table = 'admin';

Laravel convention is that table names should be plural in this case: https://laravel.com/docs/5.6/eloquent

So I recommend you to change your migration from 'admin' to 'admins'.