Saher Siddiqui
Saher Siddiqui

Reputation: 363

How to pass id in update route of resource controller?

Current code

<form action="{{route('sub-admin.update',['id' => 1])}}" id="edit-sub-admin" method="POST" enctype="multipart/form-data">
</form>

Current Output

<form action="http://localhost:8000/admin/sub-admin" id="edit-sub-admin" method="POST" enctype="multipart/form-data">
</form>

Expected Output

<form action="http://localhost:8000/admin/sub-admin/1" id="edit-sub-admin" method="POST" enctype="multipart/form-data">
</form>

Can anyone help me out ?

Upvotes: 2

Views: 3761

Answers (4)

Mumble-Architect
Mumble-Architect

Reputation: 47


//web routes

Route::post('update/{$id}', 'ControllerName@functionName');

Upvotes: 0

Jithesh Jose
Jithesh Jose

Reputation: 1814

Try this code..

  <form action="{{route('sub-admin.update',['id' => 1])}}" method="POST" enctype="multipart/form-data"></form>

OR

  <form action="{{route('sub-admin.update',1)}}" method="POST" enctype="multipart/form-data"></form>

Your resource route should be like this..

  Route::resource('sub-admin', 'SubAdminController');

Upvotes: 1

smartrahat
smartrahat

Reputation: 5659

No need to put the id on array. Just use the id as a second parameter of route() function.

Example:

<form action="{{route('sub-admin.update',1)}}" id="edit-sub-admin" method="POST" enctype="multipart/form-data">
</form>

Upvotes: 2

Niroj Maharjan
Niroj Maharjan

Reputation: 99

Try using the id instead of id => some value

<form action="{{route('sub-admin.update',[1])}}" id="edit-sub-admin" method="POST" enctype="multipart/form-data">

Upvotes: 0

Related Questions