vendredi 27 novembre 2015

Laravel 5.1 firstOrNew with relationships

How can I use firstOrNew method with Laravel relationships.

I have the following relationship:

/**
 * The rows that belong to the timesheet.
 *
 * @return Object
 */
public function rowTimesheet()
{
    return $this->hasMany('App\Models\Timesheet\RowTimesheet');
}

I am trying to create a new row for the timesheet in the database using the following. I don't get any errors, but the row doesn't get inserted.

Any ideas?

/**
 * Create timesheet rows.
 *
 * @param $id
 * @param $row
 */
public function createTimesheetRow($id, $row) 
{
    return $this->timesheet->find($id)->rowTimesheet()->firstOrNew($row);
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire