Eloquent - fields that match in a record if firstOrNew fails with multiple conditions

Viewed 118

Suppose I have the following create code

$User = User::firstOrNew(
  array(
    'username' => $args['username'],
    'phone_no' => $args['phone_no']
  ),
  array(
    'otherDetails' => 'here',
  )
);

$User->save();

if (!$User->wasRecentlyCreated) {
  // code to check which field has same record in db    
}

After confirming that the insertion was not able to push through because an existing record has been fetched, is there any way I can find out which of either username or phone_no has the same data in the User table? Without using another where lookup in the model. Thanks.

0 Answers
Related