Questions tagged upsert

Explore the latest questions and answers asked by our top developers.

Laravel 8 upsert doesn’t work as expected

I’m trying use upsert as explained here ( and in 8.x doc but it is not working as expected. CartItem::upsert( [ [ "id" => 105, "unit_price" => 146.5124, "price" => 293.0248, "unit_taxes" => 28.22, "taxes" => 56.44, "custom_fields" => ‘{"options":{"estado":15,"user_id":1},"calculated_price":146.5124,"calculated_tax_price":28.22}’ ], [ "id" => 106, "unit_price" => 113.8824, "price" => 227.7648, "unit_taxes" => 11.54, "taxes" […]

By Denis Spalenza
Categorised as eloquent, laravel, upsert Tagged , ,

in Laravel how to covert this code Create obeject into upsert

function xxxxx() { ……. $data=$request->all() $organisationGroup = new OrgrpOrganisationGroup; $organisationGroup->column1 = $data[‘Id’]; $organisationGroup->culumn2 = $data[‘Code’]; $organisationGroup->Name = $data[‘GName’]; $organisationGroup->country = $data[‘Country’]; $organisationGroup->state =$data[‘State’]; $organisationGroup->city = $data[‘City’]; $organisationGroup->MSCURID =$data[‘Currency’]; $organisationGroup->codeph = 91; $organisationGroup->Logo = ’empty’; $organisationGroup->Mobile = $data[‘Mobile’]; $organisationGroup->Address = $data[‘Address’]; $organisationGroup->Landmark = $data[‘Nearest_Landmark’]; $organisationGroup->Email = $data[‘Email’]; $organisationGroup->Latitude = $data[‘Latitude’]; $organisationGroup->ORGRPHQLongitude = $data[‘Longitude’]; } $organisationGroup->save() this […]

By rahul krishna
Categorised as ajax, jquery, laravel, upsert Tagged , , ,

Can I use upsert in eloquent relation model?

I just find that laravel 8 has new multiple createOrUpdate function upsert and I want to know how should I deal with parent id. At this point, upsert doesn’t fill parent object id. Is there a way that I can inject parent object id manually or should I just avoid this situation at all? I […]

By GatesPlan
Categorised as laravel, upsert Tagged ,

Laravel Upsert with conditional columns only on insert?

When doing an upsert can I define certain columns that should only be used when inserting not updating? Source: Laravel

By James4645
Categorised as eloquent, laravel, postgresql, upsert Tagged , , ,

Laravel Upsert with Soft Deleted Model

I’ve got a model that includes a lot of voters, which have soft deletes enabled on them. When I get a new electoral register and list of voters, I want to upload these, and bulk upsert() using Laravel’s new functionality. To do this, I delete (i.e. soft delete) all the voters in the ward, then […]

By Andreas Christodoulou
Categorised as laravel, sql, upsert Tagged , ,

Laravel upsert only if two columns conflict

I have the following table id | invoice_id | position | item_name | qty —|————|———-|———–|—- 1 | 1234 | 200 | shaft | 2 2 | 1234 | 202 | spear | 1 3 | 1235 | 200 | shaft | 10 4 | 1235 | 202 | spear | 20 How can I "target" […]

By The VaLo
Categorised as laravel, mysql, upsert Tagged , ,

Laravel Mass Assignment without id( autoincrement)

would like to know if it’s possible to insert or upsert in Laravel by keeping the Autoincrement id blank. here is my table migration $table->id(); // Autoincrement $table->string("description"); $table->string("part_number"); $table->string("serial_number"); $table->smallInteger("qty"); here is the data that I would like to upsert. when I try to the upsert with $data1, I get an error. haven’t tried […]

By Pandurang
Categorised as eloquent, laravel, mysql, upsert Tagged , , ,

Laravel 8 upsert with DB::Raw query

I am looking to use Laravel 8’s native upsert function to import a batch of products. When using the package I could e.g. just use the following to update an image when not existing in the DB model: Product::upsert( $values, $target, [ ‘image’ => DB::raw("if(`image` is null, values(`image`), `image`)"), // TODO: Add the other […]

By Intergalactisch
Categorised as laravel, laravel-8, php, upsert Tagged , , ,

Laravel updateOrCreate reflecting table but not updating collection

I want to insert date only when updateOrCreate works as CREATE & update date only when updateOrCreate works as UPDATE. UpdateOrCreate Method work absolute fine. but when i am trying to check +wasRecentlyCreated so that i can update or insert date accordingly. this property is always showing +wasRecentlyCreated: false. However, data updating & creating as […]

By H45H
Categorised as eloquent, laravel, orm, php, upsert

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us