vendredi 27 novembre 2015

Laravel 5.1: Get ID from firstOrNew method

I have the following function which creates a new record in the database if one doesn't already exists - if one exists, it updates it. The problem is that it returns true and therefore I can't get the ID of the inserted or updated record.

/**
 * Save timesheet.
 *
 * @param $token
 * @param $data
 */
public function saveTimesheet($token, $data) 
{
    return $this->timesheet->firstOrNew($token)->fill($data)->save();
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire