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([Conditions],[fields with value]);

Example

                                        

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

Suggest An Answer

No suggestions Available!