Ramu Ramu
Ramu Ramu

Reputation: 37

laravel updating editing database record - getting error when submitting the form

I am using this code to edit database record :

public function service_edit($id)
{
    $service = Service::find($id);
    return view('Super_Admin/service/.service_edit')->with('service', $service);
}

public function service_update(Request $request, $id)
{
    $service = Service::find($id);
    $input['title_name'] = strtoupper ($request['title_name']);
    $input['link'] = strtoupper ($request['link']);
    $input['note'] = strtoupper ($request['note']);
    $input['image'] = time().'.'.$request->

    image->getClientOriginalExtension();
    $folder1 = public_path('WEBSITE-FILE/SERVICE/1');
    $path1 = $folder1 . $input['image']; // path 1
    $request->image->move($folder1, $input['image']);
    $path2 = public_path('WEBSITE-FILE/SERVICE/2').$input['image'];// path 2
    $path3 = public_path('WEBSITE-FILE/SERVICE/3'). $input['image']; // path 3
    $path4 = public_path('WEBSITE-FILE/SERVICE/4'). $input['image']; // path 4

    \File::copy($path1, $path2);
    \File::copy($path1, $path3);
    \File::copy($path1, $path4);

    $service->save();

    return back()->with('success','UPDATED SUCCESSFULLY .');
}

I am facing this error when I submit the form

"Call to a member function save() on array"

Upvotes: 0

Views: 640

Answers (3)

porloscerros Ψ
porloscerros Ψ

Reputation: 5098

$service is where you have to save, not $input.
You must to assign the values ​​of the request to the $service variable (Service Object) and then save it.
Try in this way:

public function service_update(Request $request, $id)
{
    $service = Service::find($id);
    $service->title_name = strtoupper ($request->title_name);
    $service->link = strtoupper ($request->link);
    $service->note = strtoupper ($request->note);
    $service->image = time().'.'.$request->file('image')->getClientOriginalExtension();

    // ...

    $service->save();

    return back()->with('success','UPDATED SUCCESSFULLY .');
}

Upvotes: 1

jai
jai

Reputation: 547

change the following line and try

$input= Service::find($id);

Upvotes: 0

Leonardo Rossi
Leonardo Rossi

Reputation: 3022

You initialize $input as an array, then you call $input->save(), that's why the error is raised.

Maybe you wanted to use $service in place of $input ?

Upvotes: 1

Related Questions