【发布时间】:2015-11-28 00:12:59
【问题描述】:
如何在 Laravel 关系中使用 firstOrNew 方法。
我有以下关系:
/**
* The rows that belong to the timesheet.
*
* @return Object
*/
public function rowTimesheet()
{
return $this->hasMany('App\Models\Timesheet\RowTimesheet');
}
我正在尝试使用以下内容为数据库中的时间表创建一个新行。我没有收到任何错误,但没有插入该行。
有什么想法吗?
/**
* Create timesheet rows.
*
* @param $id
* @param $row
*/
public function createTimesheetRow($id, $row)
{
return $this->timesheet->find($id)->rowTimesheet()->firstOrNew($row);
}
【问题讨论】:
-
在
->firstOrNew($row)之后尝试了->save()?