Answers for "insert data if not exists in database while updating laravel 8"

PHP
2

laravel db does not exists

if (DB::table('orders')->where('finalized', 1)->exists()) {
    // ...
}

if (DB::table('orders')->where('finalized', 1)->doesntExist()) {
    // ...
}
Posted by: Guest on August-14-2021
0

laravel migrate if not exists

if (!Schema::hasTable('tblCategory')) {
     Schema::create('tblCategory', function($table){
            $table->engine = 'InnoDB';
            $table->increments('CategoryID');
            $table->string('Category', 40);
            $table->unique('Category', 'tblCategory_UK_Category');
            $table->timestamps();
    }
}
Posted by: Guest on June-16-2021
1

laravel update if exists or create

$flight = App\Flight::updateOrCreate(
    ['departure' => 'Oakland', 'destination' => 'San Diego'],
    ['price' => 99]
);
Posted by: Guest on June-20-2021

Code answers related to "insert data if not exists in database while updating laravel 8"

Browse Popular Code Answers by Language