V4n*_*ll4 4 php laravel laravel-5
我有以下功能,如果一个新记录尚不存在,它会在数据库中创建一个新记录 - 如果存在,则更新它.问题是它返回true
,因此我无法获取插入或更新记录的ID.
/**
* Save timesheet.
*
* @param $token
* @param $data
*/
public function saveTimesheet($token, $data)
{
return $this->timesheet->firstOrNew($token)->fill($data)->save();
}
Run Code Online (Sandbox Code Playgroud)
首先创建新模型然后保存它,id将自动设置在模型中.
/**
* Save timesheet.
*
* @param $token
* @param $data
*/
public function saveTimesheet($token, $data)
{
// Set the data
$model = $this->timesheet->firstOrNew($token)->fill($data);
// Save the model
$model->save();
// Return the id
return $model->id;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
954 次 |
最近记录: |