I'm new to Laravel. I am using laravel 5.4 and trying to validate and update data in a model. Code looks like this:
Route
Route::resource ('contribution-structure', 'ContributionStructureController');
ContributionStructureController
public function update(Request $request, $id)
{
//
$data = $this->validate($request, [
'employer_name' => 'required|min:3',
]);
$plansubmission = PlanSubmission::find($id);
$plansubmission->update($data);
}
The validation works but when I update I get an error saying:
Argument 1 passed to Illuminate\Database\Eloquent\Model::update() must be of the type array, null given, called in C:\xampp\htdocs\tapp\app\Http\Controllers\ContributionStructureController.php on line 84 and defined
$plansubmission-> employer_name = $request ->only('employer_name')
use like this?? – A.A Noman$plansubmission->employer_name = $request ->get('employer_name'); $plansubmission->save()
. Asonly()
returns an array, and you need to be sure to save the model afterwards, whichupdated()
does automatically. – jfadich