Reputation: 571
I want to do an insert in the database, but I want to make an insert ignore, to ignore if there is already a value in the primary key. How do I do this with eloquent? this is my code in eloquent:
return LogMonth::insert(array('users_id' => $user,
'log' => $Log,
'month' => $Month,
'year' => $Mear,));
Upvotes: 4
Views: 3593
Reputation: 220026
Use the firstOrCreate
method:
return Log::firstOrCreate([
'users_id' => $user,
'log' => $Log,
'month' => $Month,
'year' => $Year,
]);
Upvotes: 6