DELETE request in laravel
I have a categories page and create a remove button which to remove it the categories, the image as below: 
So the problem is show me 'MethodNotAllowedHttpException'
Alright. Here is Route file
Route::delete('removeCategory/id','AdminController@removeCategory');
Controller file
public function removeCategory(Request $id)
$cats = cats::find($id);
$cats->delete();
and View file
@foreach($data as $product)
<tr style="height:50px">
<td style="padding:10px">$product->cat_name</td>
<td><a class="btn btn-sm btn-fill btn-primary"
href="url('/admin/editCategory')/$product->id">Edit</a></td>
<td><a href="url('admin/removeCategory')/$product->id" onclick="return confirm('Are you sure?')"
class="btn btn-sm btn-fill btn-primary">Remove</a></td>
</tr>
@endforeach
Thanks for anyone share the info to me, I have tried it but showing me this error message.
javascript php laravel
add a comment |
I have a categories page and create a remove button which to remove it the categories, the image as below: 
So the problem is show me 'MethodNotAllowedHttpException'
Alright. Here is Route file
Route::delete('removeCategory/id','AdminController@removeCategory');
Controller file
public function removeCategory(Request $id)
$cats = cats::find($id);
$cats->delete();
and View file
@foreach($data as $product)
<tr style="height:50px">
<td style="padding:10px">$product->cat_name</td>
<td><a class="btn btn-sm btn-fill btn-primary"
href="url('/admin/editCategory')/$product->id">Edit</a></td>
<td><a href="url('admin/removeCategory')/$product->id" onclick="return confirm('Are you sure?')"
class="btn btn-sm btn-fill btn-primary">Remove</a></td>
</tr>
@endforeach
Thanks for anyone share the info to me, I have tried it but showing me this error message.
javascript php laravel
Don't forget to use!! method_field('delete') !!
– Peon
Nov 15 '18 at 14:44
Also, your onClick validation will always work, if JS is disabled, meaning, it will delete by default and not delete, if JS confirm works. If you want to make a validation, make sure that by default it doesn't work, and will work ONLY if you successfully validate request.
– Peon
Nov 15 '18 at 14:47
add a comment |
I have a categories page and create a remove button which to remove it the categories, the image as below: 
So the problem is show me 'MethodNotAllowedHttpException'
Alright. Here is Route file
Route::delete('removeCategory/id','AdminController@removeCategory');
Controller file
public function removeCategory(Request $id)
$cats = cats::find($id);
$cats->delete();
and View file
@foreach($data as $product)
<tr style="height:50px">
<td style="padding:10px">$product->cat_name</td>
<td><a class="btn btn-sm btn-fill btn-primary"
href="url('/admin/editCategory')/$product->id">Edit</a></td>
<td><a href="url('admin/removeCategory')/$product->id" onclick="return confirm('Are you sure?')"
class="btn btn-sm btn-fill btn-primary">Remove</a></td>
</tr>
@endforeach
Thanks for anyone share the info to me, I have tried it but showing me this error message.
javascript php laravel
I have a categories page and create a remove button which to remove it the categories, the image as below: 
So the problem is show me 'MethodNotAllowedHttpException'
Alright. Here is Route file
Route::delete('removeCategory/id','AdminController@removeCategory');
Controller file
public function removeCategory(Request $id)
$cats = cats::find($id);
$cats->delete();
and View file
@foreach($data as $product)
<tr style="height:50px">
<td style="padding:10px">$product->cat_name</td>
<td><a class="btn btn-sm btn-fill btn-primary"
href="url('/admin/editCategory')/$product->id">Edit</a></td>
<td><a href="url('admin/removeCategory')/$product->id" onclick="return confirm('Are you sure?')"
class="btn btn-sm btn-fill btn-primary">Remove</a></td>
</tr>
@endforeach
Thanks for anyone share the info to me, I have tried it but showing me this error message.
javascript php laravel
javascript php laravel
edited Nov 15 '18 at 15:17
lun7code
asked Nov 15 '18 at 14:37
lun7codelun7code
548
548
Don't forget to use!! method_field('delete') !!
– Peon
Nov 15 '18 at 14:44
Also, your onClick validation will always work, if JS is disabled, meaning, it will delete by default and not delete, if JS confirm works. If you want to make a validation, make sure that by default it doesn't work, and will work ONLY if you successfully validate request.
– Peon
Nov 15 '18 at 14:47
add a comment |
Don't forget to use!! method_field('delete') !!
– Peon
Nov 15 '18 at 14:44
Also, your onClick validation will always work, if JS is disabled, meaning, it will delete by default and not delete, if JS confirm works. If you want to make a validation, make sure that by default it doesn't work, and will work ONLY if you successfully validate request.
– Peon
Nov 15 '18 at 14:47
Don't forget to use
!! method_field('delete') !!– Peon
Nov 15 '18 at 14:44
Don't forget to use
!! method_field('delete') !!– Peon
Nov 15 '18 at 14:44
Also, your onClick validation will always work, if JS is disabled, meaning, it will delete by default and not delete, if JS confirm works. If you want to make a validation, make sure that by default it doesn't work, and will work ONLY if you successfully validate request.
– Peon
Nov 15 '18 at 14:47
Also, your onClick validation will always work, if JS is disabled, meaning, it will delete by default and not delete, if JS confirm works. If you want to make a validation, make sure that by default it doesn't work, and will work ONLY if you successfully validate request.
– Peon
Nov 15 '18 at 14:47
add a comment |
4 Answers
4
active
oldest
votes
Since You want to do it without complicating the code with ajax,
solution is simply sending POST request and defining DELETE method as hidden field.
For simplicity You can add that field using method_field helper:
@foreach($data as $product)
<tr style="height:50px">
<td style="padding:10px">$product->cat_name</td>
<td><a class="btn btn-sm btn-fill btn-primary"
href="url('/admin/editCategory')/$product->id">Edit</a></td>
<td>
<form
method="post"
action="url(''admin/removeCategory')/$product->id">
!! Form::token() !!
method_field('DELETE')
<button
type="submit"
onclick="return confirm('Are you sure?')"
class="btn btn-sm btn-fill btn-primary">Remove</button>
</form>
</td>
</tr>
@endforeach
and make sure after deleting object it's returning back to listing:
public function removeCategory($id)
$Cat = cats::find($id);
if ($Cat)
$Cat->delete();
return redirect()->back();
Yup. I have tried the method you sharing to do it, but it still showing MethodNotAllowedHttpException error even I do it through a form.
– lun7code
Nov 15 '18 at 15:19
1
thanks for everyone especially answer from num8er and Devon! :)
– lun7code
Nov 15 '18 at 15:48
@lun7code it worked?
– num8er
Nov 15 '18 at 15:57
1
yes. Indeed. Is a correct answer and I vote for the acceptance answer so anyone those have same issue can be use as reference.
– lun7code
Nov 16 '18 at 2:03
add a comment |
MethodNotAllowedHttpException tells us that we tried to request the server with a http method type which is not supported at that endpoint. For example you tried to do a GET request on an url which only allows DELETE.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
add a comment |
Try editing your route to this: Route::get('removeCategory/id','AdminController@removeCategory');
Then edit your controller to this:
public function removeCategory($id)
$cats = cats::find($id);
$cats->delete();
return response(['Message' => 'This request has been deleted'], 200);
This is an alternative to the answer provided above, though I would recommend sticking to the answer provided by num8er.
add a comment |
You must submit a DELETE request. Look at num8er's answer for this. You don't have to do it through a form, you can do it through AJAX, but just using
<a hrefwill result in a GET request.You are also type hinting
$idas a Request object in the controller method.
Therefore, Laravel will provide you with a Request object instead of the number passed as a parameter in the URL. You need to remove the type hinting on that parameter, or use a type that actually fits:
public function removeCategory($id)
lol.....remove the request is works! thanks!
– lun7code
Nov 15 '18 at 15:47
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321805%2fdelete-request-in-laravel%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Since You want to do it without complicating the code with ajax,
solution is simply sending POST request and defining DELETE method as hidden field.
For simplicity You can add that field using method_field helper:
@foreach($data as $product)
<tr style="height:50px">
<td style="padding:10px">$product->cat_name</td>
<td><a class="btn btn-sm btn-fill btn-primary"
href="url('/admin/editCategory')/$product->id">Edit</a></td>
<td>
<form
method="post"
action="url(''admin/removeCategory')/$product->id">
!! Form::token() !!
method_field('DELETE')
<button
type="submit"
onclick="return confirm('Are you sure?')"
class="btn btn-sm btn-fill btn-primary">Remove</button>
</form>
</td>
</tr>
@endforeach
and make sure after deleting object it's returning back to listing:
public function removeCategory($id)
$Cat = cats::find($id);
if ($Cat)
$Cat->delete();
return redirect()->back();
Yup. I have tried the method you sharing to do it, but it still showing MethodNotAllowedHttpException error even I do it through a form.
– lun7code
Nov 15 '18 at 15:19
1
thanks for everyone especially answer from num8er and Devon! :)
– lun7code
Nov 15 '18 at 15:48
@lun7code it worked?
– num8er
Nov 15 '18 at 15:57
1
yes. Indeed. Is a correct answer and I vote for the acceptance answer so anyone those have same issue can be use as reference.
– lun7code
Nov 16 '18 at 2:03
add a comment |
Since You want to do it without complicating the code with ajax,
solution is simply sending POST request and defining DELETE method as hidden field.
For simplicity You can add that field using method_field helper:
@foreach($data as $product)
<tr style="height:50px">
<td style="padding:10px">$product->cat_name</td>
<td><a class="btn btn-sm btn-fill btn-primary"
href="url('/admin/editCategory')/$product->id">Edit</a></td>
<td>
<form
method="post"
action="url(''admin/removeCategory')/$product->id">
!! Form::token() !!
method_field('DELETE')
<button
type="submit"
onclick="return confirm('Are you sure?')"
class="btn btn-sm btn-fill btn-primary">Remove</button>
</form>
</td>
</tr>
@endforeach
and make sure after deleting object it's returning back to listing:
public function removeCategory($id)
$Cat = cats::find($id);
if ($Cat)
$Cat->delete();
return redirect()->back();
Yup. I have tried the method you sharing to do it, but it still showing MethodNotAllowedHttpException error even I do it through a form.
– lun7code
Nov 15 '18 at 15:19
1
thanks for everyone especially answer from num8er and Devon! :)
– lun7code
Nov 15 '18 at 15:48
@lun7code it worked?
– num8er
Nov 15 '18 at 15:57
1
yes. Indeed. Is a correct answer and I vote for the acceptance answer so anyone those have same issue can be use as reference.
– lun7code
Nov 16 '18 at 2:03
add a comment |
Since You want to do it without complicating the code with ajax,
solution is simply sending POST request and defining DELETE method as hidden field.
For simplicity You can add that field using method_field helper:
@foreach($data as $product)
<tr style="height:50px">
<td style="padding:10px">$product->cat_name</td>
<td><a class="btn btn-sm btn-fill btn-primary"
href="url('/admin/editCategory')/$product->id">Edit</a></td>
<td>
<form
method="post"
action="url(''admin/removeCategory')/$product->id">
!! Form::token() !!
method_field('DELETE')
<button
type="submit"
onclick="return confirm('Are you sure?')"
class="btn btn-sm btn-fill btn-primary">Remove</button>
</form>
</td>
</tr>
@endforeach
and make sure after deleting object it's returning back to listing:
public function removeCategory($id)
$Cat = cats::find($id);
if ($Cat)
$Cat->delete();
return redirect()->back();
Since You want to do it without complicating the code with ajax,
solution is simply sending POST request and defining DELETE method as hidden field.
For simplicity You can add that field using method_field helper:
@foreach($data as $product)
<tr style="height:50px">
<td style="padding:10px">$product->cat_name</td>
<td><a class="btn btn-sm btn-fill btn-primary"
href="url('/admin/editCategory')/$product->id">Edit</a></td>
<td>
<form
method="post"
action="url(''admin/removeCategory')/$product->id">
!! Form::token() !!
method_field('DELETE')
<button
type="submit"
onclick="return confirm('Are you sure?')"
class="btn btn-sm btn-fill btn-primary">Remove</button>
</form>
</td>
</tr>
@endforeach
and make sure after deleting object it's returning back to listing:
public function removeCategory($id)
$Cat = cats::find($id);
if ($Cat)
$Cat->delete();
return redirect()->back();
edited Nov 15 '18 at 17:51
answered Nov 15 '18 at 14:40
num8ernum8er
11.9k22240
11.9k22240
Yup. I have tried the method you sharing to do it, but it still showing MethodNotAllowedHttpException error even I do it through a form.
– lun7code
Nov 15 '18 at 15:19
1
thanks for everyone especially answer from num8er and Devon! :)
– lun7code
Nov 15 '18 at 15:48
@lun7code it worked?
– num8er
Nov 15 '18 at 15:57
1
yes. Indeed. Is a correct answer and I vote for the acceptance answer so anyone those have same issue can be use as reference.
– lun7code
Nov 16 '18 at 2:03
add a comment |
Yup. I have tried the method you sharing to do it, but it still showing MethodNotAllowedHttpException error even I do it through a form.
– lun7code
Nov 15 '18 at 15:19
1
thanks for everyone especially answer from num8er and Devon! :)
– lun7code
Nov 15 '18 at 15:48
@lun7code it worked?
– num8er
Nov 15 '18 at 15:57
1
yes. Indeed. Is a correct answer and I vote for the acceptance answer so anyone those have same issue can be use as reference.
– lun7code
Nov 16 '18 at 2:03
Yup. I have tried the method you sharing to do it, but it still showing MethodNotAllowedHttpException error even I do it through a form.
– lun7code
Nov 15 '18 at 15:19
Yup. I have tried the method you sharing to do it, but it still showing MethodNotAllowedHttpException error even I do it through a form.
– lun7code
Nov 15 '18 at 15:19
1
1
thanks for everyone especially answer from num8er and Devon! :)
– lun7code
Nov 15 '18 at 15:48
thanks for everyone especially answer from num8er and Devon! :)
– lun7code
Nov 15 '18 at 15:48
@lun7code it worked?
– num8er
Nov 15 '18 at 15:57
@lun7code it worked?
– num8er
Nov 15 '18 at 15:57
1
1
yes. Indeed. Is a correct answer and I vote for the acceptance answer so anyone those have same issue can be use as reference.
– lun7code
Nov 16 '18 at 2:03
yes. Indeed. Is a correct answer and I vote for the acceptance answer so anyone those have same issue can be use as reference.
– lun7code
Nov 16 '18 at 2:03
add a comment |
MethodNotAllowedHttpException tells us that we tried to request the server with a http method type which is not supported at that endpoint. For example you tried to do a GET request on an url which only allows DELETE.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
add a comment |
MethodNotAllowedHttpException tells us that we tried to request the server with a http method type which is not supported at that endpoint. For example you tried to do a GET request on an url which only allows DELETE.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
add a comment |
MethodNotAllowedHttpException tells us that we tried to request the server with a http method type which is not supported at that endpoint. For example you tried to do a GET request on an url which only allows DELETE.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
MethodNotAllowedHttpException tells us that we tried to request the server with a http method type which is not supported at that endpoint. For example you tried to do a GET request on an url which only allows DELETE.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
answered Nov 15 '18 at 14:39
messerbillmesserbill
3,1031225
3,1031225
add a comment |
add a comment |
Try editing your route to this: Route::get('removeCategory/id','AdminController@removeCategory');
Then edit your controller to this:
public function removeCategory($id)
$cats = cats::find($id);
$cats->delete();
return response(['Message' => 'This request has been deleted'], 200);
This is an alternative to the answer provided above, though I would recommend sticking to the answer provided by num8er.
add a comment |
Try editing your route to this: Route::get('removeCategory/id','AdminController@removeCategory');
Then edit your controller to this:
public function removeCategory($id)
$cats = cats::find($id);
$cats->delete();
return response(['Message' => 'This request has been deleted'], 200);
This is an alternative to the answer provided above, though I would recommend sticking to the answer provided by num8er.
add a comment |
Try editing your route to this: Route::get('removeCategory/id','AdminController@removeCategory');
Then edit your controller to this:
public function removeCategory($id)
$cats = cats::find($id);
$cats->delete();
return response(['Message' => 'This request has been deleted'], 200);
This is an alternative to the answer provided above, though I would recommend sticking to the answer provided by num8er.
Try editing your route to this: Route::get('removeCategory/id','AdminController@removeCategory');
Then edit your controller to this:
public function removeCategory($id)
$cats = cats::find($id);
$cats->delete();
return response(['Message' => 'This request has been deleted'], 200);
This is an alternative to the answer provided above, though I would recommend sticking to the answer provided by num8er.
answered Nov 15 '18 at 14:49
Solomon AntoineSolomon Antoine
172110
172110
add a comment |
add a comment |
You must submit a DELETE request. Look at num8er's answer for this. You don't have to do it through a form, you can do it through AJAX, but just using
<a hrefwill result in a GET request.You are also type hinting
$idas a Request object in the controller method.
Therefore, Laravel will provide you with a Request object instead of the number passed as a parameter in the URL. You need to remove the type hinting on that parameter, or use a type that actually fits:
public function removeCategory($id)
lol.....remove the request is works! thanks!
– lun7code
Nov 15 '18 at 15:47
add a comment |
You must submit a DELETE request. Look at num8er's answer for this. You don't have to do it through a form, you can do it through AJAX, but just using
<a hrefwill result in a GET request.You are also type hinting
$idas a Request object in the controller method.
Therefore, Laravel will provide you with a Request object instead of the number passed as a parameter in the URL. You need to remove the type hinting on that parameter, or use a type that actually fits:
public function removeCategory($id)
lol.....remove the request is works! thanks!
– lun7code
Nov 15 '18 at 15:47
add a comment |
You must submit a DELETE request. Look at num8er's answer for this. You don't have to do it through a form, you can do it through AJAX, but just using
<a hrefwill result in a GET request.You are also type hinting
$idas a Request object in the controller method.
Therefore, Laravel will provide you with a Request object instead of the number passed as a parameter in the URL. You need to remove the type hinting on that parameter, or use a type that actually fits:
public function removeCategory($id)
You must submit a DELETE request. Look at num8er's answer for this. You don't have to do it through a form, you can do it through AJAX, but just using
<a hrefwill result in a GET request.You are also type hinting
$idas a Request object in the controller method.
Therefore, Laravel will provide you with a Request object instead of the number passed as a parameter in the URL. You need to remove the type hinting on that parameter, or use a type that actually fits:
public function removeCategory($id)
answered Nov 15 '18 at 14:51
DevonDevon
23.5k42747
23.5k42747
lol.....remove the request is works! thanks!
– lun7code
Nov 15 '18 at 15:47
add a comment |
lol.....remove the request is works! thanks!
– lun7code
Nov 15 '18 at 15:47
lol.....remove the request is works! thanks!
– lun7code
Nov 15 '18 at 15:47
lol.....remove the request is works! thanks!
– lun7code
Nov 15 '18 at 15:47
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321805%2fdelete-request-in-laravel%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Don't forget to use
!! method_field('delete') !!– Peon
Nov 15 '18 at 14:44
Also, your onClick validation will always work, if JS is disabled, meaning, it will delete by default and not delete, if JS confirm works. If you want to make a validation, make sure that by default it doesn't work, and will work ONLY if you successfully validate request.
– Peon
Nov 15 '18 at 14:47