Php Laravel 5.1 firstOrNew与关系
如何将Php Laravel 5.1 firstOrNew与关系,php,laravel,laravel-5,Php,Laravel,Laravel 5,如何将firstOrNew方法用于Laravel关系 我有以下关系: /** * The rows that belong to the timesheet. * * @return Object */ public function rowTimesheet() { return $this->hasMany('App\Models\Timesheet\RowTimesheet'); } 我正在尝试使用以下命令在数据库中为时间表创建新行。我没有得到任何错误,但是没有插入
firstOrNew
方法用于Laravel关系
我有以下关系:
/**
* 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
firstOrNew返回的模型尚未持久化到数据库。您需要手动调用save来保存它
所以你可以试试
public function createTimesheetRow($id, $row)
{
return $this->timesheet->find($id)->rowTimesheet()->firstOrCreate($row);
}
或
您可以在Hello about
firstOrNew
firstOrNew返回的模型尚未持久化到数据库。您需要手动调用save来保存它
所以你可以试试
public function createTimesheetRow($id, $row)
{
return $this->timesheet->find($id)->rowTimesheet()->firstOrCreate($row);
}
或
您可以在->firstOrNew($row)
之后的尝试->save()
中阅读更多信息->firstOrNew($row)
之后的尝试->save()
?