Laravel - MethodNotAllowedHttpException in RouteCollection.php line 251
My question is about upload photo with Ajax.
This is my blade:
<section class="panel">
<header class="panel-heading">
Medya Ekle
</header>
<div class="panel-body">
<form class="form-horizontal tasi-form" id="upload_form" method="post" enctype="multipart/form-data">
{{csrf_field()}}
<div class="form-group">
<label class="col-sm-2 control-label">Medya Başlığı *</label>
<div class="col-sm-10">
<input type="text" class="form-control mediaTitleTxt" name="mediaTitleTxt" autocomplete="off" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Medya *</label>
<div class="col-sm-10">
<input type="file" class="form-control mediaInput" name="mediaInput" autocomplete="off" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<button class="btn btn-success pull-right addMediaBtn">Ekle</button>
</div>
</div>
</form>
</div>
</section>
<section class="panel tasks-widget">
<header class="panel-heading">
Medyalar
</header>
<div class="panel-body">
</div>
</section>
<!--main content end-->
This is my JS code:
let form = $("#upload_form");
form.on("submit", function (e) {
e.preventDefault();
$.ajax({
url:"/api/media/create",
method:"POST",
data:new FormData(this),
dataType:'JSON',
contentType: false,
cache: false,
processData: false,
success:function(data)
{
console.log(data);
}
});
});
This is my routes/api.php:
Route::post("media/create", "api@createMedia");
This is my controller:
public function createMedia(Request $request){
//TODO Upload image
return [$request];
}
When I click submit button I'm getting this error:
MethodNotAllowedHttpException in RouteCollection.php line 251
I can't figure it out. How can I solve this?
php laravel
|
show 4 more comments
My question is about upload photo with Ajax.
This is my blade:
<section class="panel">
<header class="panel-heading">
Medya Ekle
</header>
<div class="panel-body">
<form class="form-horizontal tasi-form" id="upload_form" method="post" enctype="multipart/form-data">
{{csrf_field()}}
<div class="form-group">
<label class="col-sm-2 control-label">Medya Başlığı *</label>
<div class="col-sm-10">
<input type="text" class="form-control mediaTitleTxt" name="mediaTitleTxt" autocomplete="off" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Medya *</label>
<div class="col-sm-10">
<input type="file" class="form-control mediaInput" name="mediaInput" autocomplete="off" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<button class="btn btn-success pull-right addMediaBtn">Ekle</button>
</div>
</div>
</form>
</div>
</section>
<section class="panel tasks-widget">
<header class="panel-heading">
Medyalar
</header>
<div class="panel-body">
</div>
</section>
<!--main content end-->
This is my JS code:
let form = $("#upload_form");
form.on("submit", function (e) {
e.preventDefault();
$.ajax({
url:"/api/media/create",
method:"POST",
data:new FormData(this),
dataType:'JSON',
contentType: false,
cache: false,
processData: false,
success:function(data)
{
console.log(data);
}
});
});
This is my routes/api.php:
Route::post("media/create", "api@createMedia");
This is my controller:
public function createMedia(Request $request){
//TODO Upload image
return [$request];
}
When I click submit button I'm getting this error:
MethodNotAllowedHttpException in RouteCollection.php line 251
I can't figure it out. How can I solve this?
php laravel
javascript post url is/api/media/create
but your route is justmedia/create
I guess that should be the problem ?
– sking
Jan 19 at 11:48
Route defined in the routes/api.php Within this group, the /api URI prefix is automatically applied. @sking
– M. Özdemir
Jan 19 at 11:56
do you get the error as a post error in the console or do you get the error view of laravel?
– François Lanzeray
Jan 19 at 11:59
GET localhost:8000/api/media/… 405 (Method Not Allowed) I'm getting this error. @FrançoisLanzeray
– M. Özdemir
Jan 19 at 12:01
So you get these MethodNotAllowed Exceptions when you defined a post route but you do not send a post request to this route. And as you are getting a GET error, you are sending a get. I'd guess everythings fine on the laravel part, but there seems to be a problem in you're html/js, I'll have a look into it...
– François Lanzeray
Jan 19 at 12:09
|
show 4 more comments
My question is about upload photo with Ajax.
This is my blade:
<section class="panel">
<header class="panel-heading">
Medya Ekle
</header>
<div class="panel-body">
<form class="form-horizontal tasi-form" id="upload_form" method="post" enctype="multipart/form-data">
{{csrf_field()}}
<div class="form-group">
<label class="col-sm-2 control-label">Medya Başlığı *</label>
<div class="col-sm-10">
<input type="text" class="form-control mediaTitleTxt" name="mediaTitleTxt" autocomplete="off" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Medya *</label>
<div class="col-sm-10">
<input type="file" class="form-control mediaInput" name="mediaInput" autocomplete="off" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<button class="btn btn-success pull-right addMediaBtn">Ekle</button>
</div>
</div>
</form>
</div>
</section>
<section class="panel tasks-widget">
<header class="panel-heading">
Medyalar
</header>
<div class="panel-body">
</div>
</section>
<!--main content end-->
This is my JS code:
let form = $("#upload_form");
form.on("submit", function (e) {
e.preventDefault();
$.ajax({
url:"/api/media/create",
method:"POST",
data:new FormData(this),
dataType:'JSON',
contentType: false,
cache: false,
processData: false,
success:function(data)
{
console.log(data);
}
});
});
This is my routes/api.php:
Route::post("media/create", "api@createMedia");
This is my controller:
public function createMedia(Request $request){
//TODO Upload image
return [$request];
}
When I click submit button I'm getting this error:
MethodNotAllowedHttpException in RouteCollection.php line 251
I can't figure it out. How can I solve this?
php laravel
My question is about upload photo with Ajax.
This is my blade:
<section class="panel">
<header class="panel-heading">
Medya Ekle
</header>
<div class="panel-body">
<form class="form-horizontal tasi-form" id="upload_form" method="post" enctype="multipart/form-data">
{{csrf_field()}}
<div class="form-group">
<label class="col-sm-2 control-label">Medya Başlığı *</label>
<div class="col-sm-10">
<input type="text" class="form-control mediaTitleTxt" name="mediaTitleTxt" autocomplete="off" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Medya *</label>
<div class="col-sm-10">
<input type="file" class="form-control mediaInput" name="mediaInput" autocomplete="off" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<button class="btn btn-success pull-right addMediaBtn">Ekle</button>
</div>
</div>
</form>
</div>
</section>
<section class="panel tasks-widget">
<header class="panel-heading">
Medyalar
</header>
<div class="panel-body">
</div>
</section>
<!--main content end-->
This is my JS code:
let form = $("#upload_form");
form.on("submit", function (e) {
e.preventDefault();
$.ajax({
url:"/api/media/create",
method:"POST",
data:new FormData(this),
dataType:'JSON',
contentType: false,
cache: false,
processData: false,
success:function(data)
{
console.log(data);
}
});
});
This is my routes/api.php:
Route::post("media/create", "api@createMedia");
This is my controller:
public function createMedia(Request $request){
//TODO Upload image
return [$request];
}
When I click submit button I'm getting this error:
MethodNotAllowedHttpException in RouteCollection.php line 251
I can't figure it out. How can I solve this?
php laravel
php laravel
edited Jan 19 at 11:57
M. Özdemir
asked Jan 19 at 11:35
M. ÖzdemirM. Özdemir
34
34
javascript post url is/api/media/create
but your route is justmedia/create
I guess that should be the problem ?
– sking
Jan 19 at 11:48
Route defined in the routes/api.php Within this group, the /api URI prefix is automatically applied. @sking
– M. Özdemir
Jan 19 at 11:56
do you get the error as a post error in the console or do you get the error view of laravel?
– François Lanzeray
Jan 19 at 11:59
GET localhost:8000/api/media/… 405 (Method Not Allowed) I'm getting this error. @FrançoisLanzeray
– M. Özdemir
Jan 19 at 12:01
So you get these MethodNotAllowed Exceptions when you defined a post route but you do not send a post request to this route. And as you are getting a GET error, you are sending a get. I'd guess everythings fine on the laravel part, but there seems to be a problem in you're html/js, I'll have a look into it...
– François Lanzeray
Jan 19 at 12:09
|
show 4 more comments
javascript post url is/api/media/create
but your route is justmedia/create
I guess that should be the problem ?
– sking
Jan 19 at 11:48
Route defined in the routes/api.php Within this group, the /api URI prefix is automatically applied. @sking
– M. Özdemir
Jan 19 at 11:56
do you get the error as a post error in the console or do you get the error view of laravel?
– François Lanzeray
Jan 19 at 11:59
GET localhost:8000/api/media/… 405 (Method Not Allowed) I'm getting this error. @FrançoisLanzeray
– M. Özdemir
Jan 19 at 12:01
So you get these MethodNotAllowed Exceptions when you defined a post route but you do not send a post request to this route. And as you are getting a GET error, you are sending a get. I'd guess everythings fine on the laravel part, but there seems to be a problem in you're html/js, I'll have a look into it...
– François Lanzeray
Jan 19 at 12:09
javascript post url is
/api/media/create
but your route is just media/create
I guess that should be the problem ?– sking
Jan 19 at 11:48
javascript post url is
/api/media/create
but your route is just media/create
I guess that should be the problem ?– sking
Jan 19 at 11:48
Route defined in the routes/api.php Within this group, the /api URI prefix is automatically applied. @sking
– M. Özdemir
Jan 19 at 11:56
Route defined in the routes/api.php Within this group, the /api URI prefix is automatically applied. @sking
– M. Özdemir
Jan 19 at 11:56
do you get the error as a post error in the console or do you get the error view of laravel?
– François Lanzeray
Jan 19 at 11:59
do you get the error as a post error in the console or do you get the error view of laravel?
– François Lanzeray
Jan 19 at 11:59
GET localhost:8000/api/media/… 405 (Method Not Allowed) I'm getting this error. @FrançoisLanzeray
– M. Özdemir
Jan 19 at 12:01
GET localhost:8000/api/media/… 405 (Method Not Allowed) I'm getting this error. @FrançoisLanzeray
– M. Özdemir
Jan 19 at 12:01
So you get these MethodNotAllowed Exceptions when you defined a post route but you do not send a post request to this route. And as you are getting a GET error, you are sending a get. I'd guess everythings fine on the laravel part, but there seems to be a problem in you're html/js, I'll have a look into it...
– François Lanzeray
Jan 19 at 12:09
So you get these MethodNotAllowed Exceptions when you defined a post route but you do not send a post request to this route. And as you are getting a GET error, you are sending a get. I'd guess everythings fine on the laravel part, but there seems to be a problem in you're html/js, I'll have a look into it...
– François Lanzeray
Jan 19 at 12:09
|
show 4 more comments
3 Answers
3
active
oldest
votes
Could you try to put that route in web.php ? then call it from there without including the /api/ in the link
I get same error.
– M. Özdemir
Jan 19 at 13:17
add a comment |
For anyone wondering: problem is that he used GET in his code at some point, but he fixed it by now and it's working. Please see the comments to his question for further information. Some general notes after I've seen the questions and proposed answers:
- General information about Laravel Routes can be obtained from the docs: https://laravel.com/docs/5.7/routing (make ure you use the one version that matches your laravel version)
- API Routes defined in api.php do always auto prepend api/ so theres no need to specifically type that in the route files
- Leading / in routes are not necessary
Route::get("api/test", function(){});
can be accessed by/api/test
. - However, trying to access it by using
/api/test/
results in an MethodNotAllowedException as Laravel assumes that after the / something follows as a get parameter. So be careful :)
add a comment |
It was about old jQuery version I change jQuery version and problem solved. Thanks for helping.
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%2f54266656%2flaravel-methodnotallowedhttpexception-in-routecollection-php-line-251%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Could you try to put that route in web.php ? then call it from there without including the /api/ in the link
I get same error.
– M. Özdemir
Jan 19 at 13:17
add a comment |
Could you try to put that route in web.php ? then call it from there without including the /api/ in the link
I get same error.
– M. Özdemir
Jan 19 at 13:17
add a comment |
Could you try to put that route in web.php ? then call it from there without including the /api/ in the link
Could you try to put that route in web.php ? then call it from there without including the /api/ in the link
answered Jan 19 at 13:05
KneegrowsKneegrows
54
54
I get same error.
– M. Özdemir
Jan 19 at 13:17
add a comment |
I get same error.
– M. Özdemir
Jan 19 at 13:17
I get same error.
– M. Özdemir
Jan 19 at 13:17
I get same error.
– M. Özdemir
Jan 19 at 13:17
add a comment |
For anyone wondering: problem is that he used GET in his code at some point, but he fixed it by now and it's working. Please see the comments to his question for further information. Some general notes after I've seen the questions and proposed answers:
- General information about Laravel Routes can be obtained from the docs: https://laravel.com/docs/5.7/routing (make ure you use the one version that matches your laravel version)
- API Routes defined in api.php do always auto prepend api/ so theres no need to specifically type that in the route files
- Leading / in routes are not necessary
Route::get("api/test", function(){});
can be accessed by/api/test
. - However, trying to access it by using
/api/test/
results in an MethodNotAllowedException as Laravel assumes that after the / something follows as a get parameter. So be careful :)
add a comment |
For anyone wondering: problem is that he used GET in his code at some point, but he fixed it by now and it's working. Please see the comments to his question for further information. Some general notes after I've seen the questions and proposed answers:
- General information about Laravel Routes can be obtained from the docs: https://laravel.com/docs/5.7/routing (make ure you use the one version that matches your laravel version)
- API Routes defined in api.php do always auto prepend api/ so theres no need to specifically type that in the route files
- Leading / in routes are not necessary
Route::get("api/test", function(){});
can be accessed by/api/test
. - However, trying to access it by using
/api/test/
results in an MethodNotAllowedException as Laravel assumes that after the / something follows as a get parameter. So be careful :)
add a comment |
For anyone wondering: problem is that he used GET in his code at some point, but he fixed it by now and it's working. Please see the comments to his question for further information. Some general notes after I've seen the questions and proposed answers:
- General information about Laravel Routes can be obtained from the docs: https://laravel.com/docs/5.7/routing (make ure you use the one version that matches your laravel version)
- API Routes defined in api.php do always auto prepend api/ so theres no need to specifically type that in the route files
- Leading / in routes are not necessary
Route::get("api/test", function(){});
can be accessed by/api/test
. - However, trying to access it by using
/api/test/
results in an MethodNotAllowedException as Laravel assumes that after the / something follows as a get parameter. So be careful :)
For anyone wondering: problem is that he used GET in his code at some point, but he fixed it by now and it's working. Please see the comments to his question for further information. Some general notes after I've seen the questions and proposed answers:
- General information about Laravel Routes can be obtained from the docs: https://laravel.com/docs/5.7/routing (make ure you use the one version that matches your laravel version)
- API Routes defined in api.php do always auto prepend api/ so theres no need to specifically type that in the route files
- Leading / in routes are not necessary
Route::get("api/test", function(){});
can be accessed by/api/test
. - However, trying to access it by using
/api/test/
results in an MethodNotAllowedException as Laravel assumes that after the / something follows as a get parameter. So be careful :)
edited Jan 19 at 13:34
answered Jan 19 at 13:29
François LanzerayFrançois Lanzeray
838
838
add a comment |
add a comment |
It was about old jQuery version I change jQuery version and problem solved. Thanks for helping.
add a comment |
It was about old jQuery version I change jQuery version and problem solved. Thanks for helping.
add a comment |
It was about old jQuery version I change jQuery version and problem solved. Thanks for helping.
It was about old jQuery version I change jQuery version and problem solved. Thanks for helping.
answered Jan 21 at 10:22
M. ÖzdemirM. Özdemir
34
34
add a comment |
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%2f54266656%2flaravel-methodnotallowedhttpexception-in-routecollection-php-line-251%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
javascript post url is
/api/media/create
but your route is justmedia/create
I guess that should be the problem ?– sking
Jan 19 at 11:48
Route defined in the routes/api.php Within this group, the /api URI prefix is automatically applied. @sking
– M. Özdemir
Jan 19 at 11:56
do you get the error as a post error in the console or do you get the error view of laravel?
– François Lanzeray
Jan 19 at 11:59
GET localhost:8000/api/media/… 405 (Method Not Allowed) I'm getting this error. @FrançoisLanzeray
– M. Özdemir
Jan 19 at 12:01
So you get these MethodNotAllowed Exceptions when you defined a post route but you do not send a post request to this route. And as you are getting a GET error, you are sending a get. I'd guess everythings fine on the laravel part, but there seems to be a problem in you're html/js, I'll have a look into it...
– François Lanzeray
Jan 19 at 12:09