Answers for "where not exists in laravel"

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

create if not exist laravel

Occasionally, you may need to update an existing model or create a new model if
no matching model exists. Like the firstOrCreate method, the updateOrCreate 
method persists the model, so there is no need to manually call the save method.

In the example below, if a flight exists with a departure location of Oakland 
and a destination location of San Diego, its price and discounted columns will
be updated. If no such flight exists, a new flight will be created which has 
the attributes resulting from merging the first argument array with the 
second argument array:

$flight = Flight::updateOrCreate(
    ['departure' => 'Oakland', 'destination' => 'San Diego'],
    ['price' => 99, 'discounted' => 1]
);
Posted by: Guest on July-08-2021

Browse Popular Code Answers by Language