Home > OS >  how to change url for edit in laravel
how to change url for edit in laravel

Time:12-23

I have an edit page, I have used resource controller for it. Everytime the page redirects from edit (../members/16/edit) it continues with the edit page url (../members/16/members). [where it should only take ../members] How can I remove/change url for edit.

Route

Route::resource('members', MemberController::class);

edit function

 public function edit(Member $members,$id)
    {
        $members = Member::find($id);
        return view('edit', compact('members'));
    }
    public function update(Request $request,$id)
{
    $members = Member::find($id);
    $members->name = $request->name;
    $members->save();
    return view('committee')->with('success', 'Member Updated successfully');
}



  <a  title="Edit NewsRoom Details" 
                href="'.route("members.edit",[$members->id]).'"><i ></i></a>

CodePudding user response:

You should identify what you are passing example:

<a href="{{ route('members.edit', ['members' => $members->id, 'id' => $id]) }}">...</a>

Your update method is not redirecting anywhere, it is simply loading a different view, the correct way to do it is:

public function update(Request $request,$id)
{
    $members = Member::find($id);
    $members->name = $request->name;
    $members->save();
    //return view('committee')->with('success', 'Member Updated successfully');
    return redirect()->route('members.committee')->with('success', 'Member Updated successfully');
}
  • Related