Loading…

How to use updateOrInsert() method in Laravel Query?

updateOrInsert() method is used to update an existing record in the database if matching the condition or create if no matching record exists.

Its return type is Boolean.

Syntax

DB::table(‘blogs’)->updateOrInsert([Conditons],[fields with value]);

Example

                                        

DB::table(‘blogs’)->updateOrInsert(
     ['email' => 'info@bestinterviewquestion.com', 'title' => 'Best Interview Questions'],
     ['content' => 'Test Content']
);

Suggest An Answer

No suggestions avaliable!

Latest post from Laravel Interview Questions

Ask Question