Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to change url for edit in laravel

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 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 class="btn btn-sm btn-icon btn-success" title="Edit NewsRoom Details" 
                href="'.route("members.edit",[$members->id]).'"><i class="fas fa-edit"></i></a>

>Solution :

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');
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading