1.

How to use updateOrInsert() method in Laravel Query?

Answer»

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']
);



Discussion

No Comment Found