ruffsaint's avatar

Getting error on trying to update form with image upload

    Error = Call to a member function update() on array

   public function updatebiodata(Request $request, $id)
{
    $staff = \DB::table('tblStaff')->where('StaffRef', $id);
    $this->validate($request, [
        'TownCity'           => 'required',
        'MobilePhone'        => 'required',
        'AddressLine1'       => 'required',
        'StateID'            => 'required',
        'NextofKIN'          => 'required',
        'NextofKIN_Phone'    => 'required',
        'PhotographLocation' => 'required|max:10000',

    ]);
    $image = $request->PhotographLocation;
    if ($image) {
        $imageName = $image->getClientOriginalName();
        $image->move('images/staffpics', $imageName);
        $staffs['PhotographLocation'] = $imageName;
    }

    if ($staffs->update($request->except(['_token', '_method']))) {
        return redirect()->route('staff.showfulldetails', $id)->with('success', 'Gender was updated successfully');
    } else {
        return back()->withInput()->with('error', 'Gender failed to update');
    }
}
0 likes
1 reply
Inkmonkey's avatar

I think you are not 'getting' the result from the DB. Try changing

$staff = \DB::table('tblStaff')->where('StaffRef', $id);

to

$staff = \DB::table('tblStaff')->where('StaffRef', $id)->get();

To see the difference add dd($staff) right after where you initiate the variable.

Also, you are using $staffs instead of $staff later on in your code - so that will cause trouble as well.

Please or to participate in this conversation.