I’m trying to find out What’s the shortest way to insert a new record or update it if it exists in Laravel Eloquent. Currently, I’m using the following approach to check if a record exists based on a specific key and then either insert a new record or update the existing one:
if (!Setting::where('key', $settingKey)->exists()) {
// Insert new record into database
} else {
// Update the existing record
}
Is there a shorter and better option available in Laravel for achieving the same functionality?