我想使用填充将数据保存在数据库中,但出现错误

时间:2019-08-30 00:37:00

标签: php laravel query-builder laravel-5.8

我想读取和覆盖现有数据

ProjectController.php

public function update(Request $request,$id)
{
    $param = Project::find($id);
    $param = fill($request)->save();
    return redirect('/project');
}

我收到此错误,无法使用填充

Call to undefined function App\Http\Controllers\fill()

我尝试了

$param = Project::fill($request)->save();

但是我遇到了这个错误

Non-static method Illuminate\Database\Eloquent\Model::fill() should not be called statically

这也是

public function update(Request $request,$id)
{
    $param = Project::find($id);
    $param->fill($request)->save();
    return redirect('/project');
}

就是这样

Argument 1 passed to Illuminate\Database\Eloquent\Model::fill() must be of the type array, object given, called in 

添加所有()后效果很好

$param->fill($request->all())->save();

感谢您的合作

1 个答案:

答案 0 :(得分:0)

在填充成功后使用所有内容

$param->fill($request->all())->save();