Laravel 5 SQLSTATE[42S02]: Base table or view not found Laravel 5 SQLSTATE[42S02]: Base table or view not found laravel laravel

Laravel 5 SQLSTATE[42S02]: Base table or view not found


from App\Nhanvien.php Add this variable to the class:

 protected $table = 'nhanvien';

Explanation: The "snake case", plural name of the class will be used as the table name unless another name is explicitly specified. So, in this case, Eloquent will assume the nhanvien model stores records in the nhanviens table.


As stated in the official Eloquent documentation you need to specifically set the table name in your Model definition. That is, in your App\Nhanvien.php file set the following:

<?phpnamespace App;use Illuminate\Database\Eloquent\Model;class Nhanvien extends Model{    /**     * The table associated with the model.     *     * @var string     */    protected $table = 'Nhanvien';}

or use

protected $table = 'nhanvien';

instead if your table name is full lowercase.


Check your migration file, maybe you are using Schema::table, like this:

Schema::table('table_name', function ($table) { // ... });

If you want to create a new table you must use Schema::create:

 Schema::create('table_name', function ($table)  {     // ... });

See the Laravel migration documentation for more information.

If you are using Schema::create then please provide the contents of your migration file.