Helper Helper - 1 month ago 9x
PHP Question

Schema Builder : Create Table if not exists

I am using below code in Schema Builder to create table.

Schema::create('tblCategory', function (Blueprint $table) {
$table->string('Category', 40);
$table->unique('Category', 'tblCategory_UK_Category');

Here is the problem is, if I have to create the new table, all old scripts runs and show error that table already exists.

is there any way to create table if not exists using Schema builder ?


Try this

if (!Schema::hasTable('tblCategory')) {
     // create the tblCategory table