Methodnotallowedhttpexception in routecollection php line

Содержание
  1. Laravel 5 MethodNotAllowedHttpException in RouteCollection.php line 201:
  2. 5 Answers 5
  3. Laravel XMLHttpRequest MethodNotAllowedHttpException in RouteCollection.php line 218:
  4. Laravel по-русски
  5. #1 05.11.2015 21:41:39
  6. Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:
  7. #2 06.11.2015 00:48:38
  8. Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:
  9. #3 06.11.2015 05:18:27
  10. Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:
  11. #4 06.11.2015 17:23:17
  12. Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:
  13. #5 09.11.2016 10:52:28
  14. Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:
  15. #6 09.11.2016 13:51:23
  16. Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:
  17. #7 10.11.2016 06:57:47
  18. Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:
  19. #8 10.11.2016 08:47:31
  20. Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:
  21. #9 10.11.2016 09:05:02
  22. Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:
  23. #10 10.11.2016 09:09:48
  24. Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:
  25. #11 10.11.2016 09:31:54
  26. Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:
  27. #12 10.11.2016 09:32:58
  28. Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:
  29. #13 10.11.2016 10:19:20
  30. Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:
  31. #14 10.11.2016 10:21:44
  32. Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:
  33. #15 10.11.2016 11:22:14
  34. Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:
  35. MethodNotAllowedHttpException RouteCollection.php line 218

Laravel 5 MethodNotAllowedHttpException in RouteCollection.php line 201:

I have a number of php files in my project: admin.blade.php : this files contains the admin form. When called it show the following error:

Please Log In To Manage

>"> User Name:


Password:



Route::get('/admin',array('uses'=>'student@admin')); 
public function admin() < return View::make('student.admin'); $validator = Validator::make($data = Input::all() , User::rules()); if ($validator->fails()) < return Redirect::back()->withErrors($validator)->withInput(); > else < $check = 0; $check = DB::table('admin')->get(); $username = Input::get('username'); $password = Input::get('password'); if (Auth::attempt(['username' => $username, 'password' => $password])) < return Redirect::intended('/'); >return Redirect::back()->withInput()->withErrors('That username/password combo does not exist.'); > > 

it shows the same error while i do post to both route and form and if i do get to both then i come to same page again and again after submit.

5 Answers 5

Route::get('/admin', 'UsersController@getAdminLogin'); Route::get('/admin/dashboard', 'UsersController@dashboard'); Route::post('/admin', 'UsersController@postAdminLogin'); 

admin_login.blade.php

 '/admin']) !!> 
'form-control input-sm']) !!>
'form-control input-sm']) !!>
'btn btn-primary btn-block']) !!>

dashboard.blade.php

UsersController.php

/** * Display the admin login form if not logged in, * else redirect him/her to the admin dashboard. * */ public function getAdminLogin() < if(Auth::check() && Auth::user()->role === 'admin') < return redirect('/admin/dashboard'); >return view('admin_login'); > /** * Process the login form submitted, check for the * admin credentials in the users table. If match found, * redirect him/her to the admin dashboard, else, display * the error message. * */ public function postAdminLogin(Request $request) < $this->validate($request, [ 'email' => 'required|email|exists:users,email,role,admin', 'password' => 'required' ]); $credentials = $request->only( 'email', 'password' ); if(Auth::attempt($credentials)) < return redirect('/admin/dashboard'); >else < // Your logic of invalid credentials. return 'Invalid Credentials'; >> /** * Display the dashboard to the admin if logged in, else, * redirect him/her to the admin login form. * */ public function dashboard() < if(Auth::check() && Auth::user()->role === 'admin') < return view('admin.dashboard'); >return redirect('/admin'); > 

In routes.php , you have only 1 route, i.e.,

Route::get('/admin',array('uses'=>'student@admin')); 

And there is no declaration of post method, hence, the MethodNotAllowedHttpException

Also, in your controller, you are returning the view first and then processing the form which is not going to work at all. You first need to process the form and then return the view.

As @Sulthan has suggested, you should use Form Facade . You can check out this video on Laracasts about what Form Facade is and how you should use it.

Источник

Laravel XMLHttpRequest MethodNotAllowedHttpException in RouteCollection.php line 218:

I’m uploading image using laravel php and XMLHttpRequest() and i am getting following error MethodNotAllowedHttpException in RouteCollection.php line 218 following is my javascript code that handles the form submit:

 $(document).on('submit','form',function(e)< e.preventDefault(); $form=$(this); uploadImage($form); >); function uploadImage($form)< $form.find(".progress-bar").removeClass("progress-bar-success").removeClass("progress-bar-danger"); var formdata=new FormData($form[0]); var request=new XMLHttpRequest(); // progress event. request.upload.addEventListener('progress',function(e)< var percent=Math.round(e.loaded/e.total * 100); console.log('progress: '+percent); $form.find('.progress-bar').width(percent+'%').html(percent+'%'); >); // progress completed load event request.upload.addEventListener('load',function(e)< var percent=e.loaded/e.total * 100; console.log('load: '+percent); $form.find('.progress-bar').addClass('progress-bar-success').html('upload completed'); >); request.open('post','productImage.add'); request.send(formdata); $form.on('click','.cancel',function()< request.abort(); $form.find('.progress-bar').addClass('progress-bar-danger').removeClass('progress-bar-success').html('upload aborted. '); >); > 
  
Route::group(['prefix' => 'admin'], function () < Route::get('/', function () < return view('welcome'); >); Route::auth(); Route::get('/home', [ 'uses'=>'HomeController@index', 'as'=>'home' ]); Route::post('/productAdd', [ 'uses'=>'productsController@add', 'as'=>'product.add' ]); Route::post('/productImageAdd', [ 'uses'=>'productsController@addImage', 'as'=>'productImage.add' ]); >); 
class productsController extends Controller < function add(Request $request)< $product= new product(); $product->productName=$request["name"]; $product->description=$request["description"]; $product->discount=$request["discount"]; $request->user()->products()->save($product); return redirect()->route('home'); > function addImage(Request $request) < print_r($request); >> 

Источник

Laravel по-русски

Русское сообщество разработки на PHP-фреймворке Laravel.

Страницы 1

#1 05.11.2015 21:41:39

Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:

При регистрации возникает ошибка «MethodNotAllowedHttpException in RouteCollection.php line 219»
В Роутах прописано:

Route::any('/', function() < return view('index'); >); Route::get('auth/login', 'Auth\AuthController@getLogin'); Route::get('auth/register', 'Auth\AuthController@getRegister');

В чем может быть проблема?

#2 06.11.2015 00:48:38

Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:

Так добавьте в роуты нужный метод POST, например:
Route::post(‘auth/register’, ‘Auth\AuthController@postRegister’);

#3 06.11.2015 05:18:27

Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:

Так добавьте в роуты нужный метод POST, например:
Route::post(‘auth/register’, ‘Auth\AuthController@postRegister’);

Смотрите у вас в форме метод post, в routes.php метод get описан для авторизации.

Либо поменяйте в routes.php метод на get (но это как то не очень правильно). Либо замените его на Route::post(‘auth/register’, ‘Auth\AuthController@getRegister’);

#4 06.11.2015 17:23:17

Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:

Изменено Danil (06.11.2015 17:23:25)

#5 09.11.2016 10:52:28

Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:

Не стал создавать новую тему. У меня такая ситуация:

Открываю статью на редактирование. Нажимаю «Сохранить» и получаю ошибку:
http://hostingkartinok.com/show-image.p … 7e1cd95e1b

Отображение формы редактирования:

‘articles.update’]) !!> title) !!>
alias) !!>
excerpt) !!>
content) !!>

. public function edit($id) < $article=Article::find($id); return view('articleedit',['article'=>$article]); > public function update(Request $request, $id) /* не обновляет статью. ошибка! */ < $article=Article::find($id); $article->update($request->all()); $article->save(); //return back()->with('message','Статья обновлена'); > . 
Route::get('/', [ 'uses' => 'ArticlesController@index', 'as' => 'articles' ]); Route::get('article/', 'ArticlesController@showArticle'); //страница просмотра статьи $router->resource('articles', 'ArticlesController');//создает все маршруты дл¤ манипул¤ций со стать¤ми

Открываю для себя Laravel. Как бы не закрыть.

#6 09.11.2016 13:51:23

Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:

Mick_20,
В Form::open добавьте ‘method’ => ‘patch’ в итоге получится

  Form::open(['method' => 'patch', 'route' => 'articles.update']) !!>

И отдельный роут для просмотра можно убрать, он в ресурсе уже есть

#7 10.11.2016 06:57:47

Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:

>%Mick_20,
В %%Form::open%% добавьте %%’method’ => ‘patch’%% в итоге получится
%%(php)
‘patch’, ‘route’ => ‘articles.update’]) !!>
%%
И отдельный роут для просмотра можно убрать, он в ресурсе уже есть

Отдельный роут пока не сделал. Надо разбираться.
А форма редактирования теперь другую ошибку пишет:
http://hostingkartinok.com/show-image.p … 9fa6caa1a8

Почему-то id не передается и как следствие не обновляется статья.

 public function update(Request $request, $id) < $article = Article::findOrFail($id); $article->update($request->all()); $article->save(); return back()->with('message','Статья обновлена'); >

Открываю для себя Laravel. Как бы не закрыть.

#8 10.11.2016 08:47:31

Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:

Mick_20,
Тогда сделайте так

  Form::model($article, ['method' => 'patch', 'route' => 'articles.update']) !!>

И во всех инпутах добавьте вместо $article->value параметр null что б вот так получилось

Если так не получится, то вот так попробуйте

Form::input('text', 'title' , null) !!>

Изменено TrueKanonir (10.11.2016 08:48:14)

#9 10.11.2016 09:05:02

Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:

А зачем обнулять инпуты? Я же открываю статью на редактирование?

Открываю для себя Laravel. Как бы не закрыть.

#10 10.11.2016 09:09:48

Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:

Я в общем переделал открытие формы вот так:

 array('ArticlesController@update', $article->id))) !!>

Изменено Mick_20 (10.11.2016 09:11:20)

Открываю для себя Laravel. Как бы не закрыть.

#11 10.11.2016 09:31:54

Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:

А зачем обнулять инпуты? Я же открываю статью на редактирование?

Form model binding , значения подставляются. Попробуйте как я вам в примере показал сделать. Все сработает.

#12 10.11.2016 09:32:58

Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:

Я в общем переделал открытие формы вот так:

 array('ArticlesController@update', $article->id))) !!>

Вы не указали метод patch
UPD: Он находит статью для редактирования, но при отправке формы вы не указываете id статьи. В контроллере сделайте dd($request->all()). Создайте input type hidden value=»id >>» name id

Изменено TrueKanonir (10.11.2016 09:36:58)

#13 10.11.2016 10:19:20

Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:

А зачем обнулять инпуты? Я же открываю статью на редактирование?

Form model binding , значения подставляются. Попробуйте как я вам в примере показал сделать. Все сработает.

Открываю для себя Laravel. Как бы не закрыть.

#14 10.11.2016 10:21:44

Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:

Я в общем переделал открытие формы вот так:

 array('ArticlesController@update', $article->id))) !!>

Вы не указали метод patch
UPD: Он находит статью для редактирования, но при отправке формы вы не указываете id статьи. В контроллере сделайте dd($request->all()). Создайте input type hidden value=»id >>» name id

Опять выдает: MethodNotAllowedHttpException in RouteCollection.php line 218:

Открываю для себя Laravel. Как бы не закрыть.

#15 10.11.2016 11:22:14

Re: Ошибка MethodNotAllowedHttpException in RouteCollection.php line 219:

Я в общем переделал открытие формы вот так:

 array('ArticlesController@update', $article->id))) !!>

Вы не указали метод patch
UPD: Он находит статью для редактирования, но при отправке формы вы не указываете id статьи. В контроллере сделайте dd($request->all()). Создайте input type hidden value=»id >>» name id

Опять выдает: MethodNotAllowedHttpException in RouteCollection.php line 218:

Сделал у себя, на только что установленном фрейме. Все пашет.
Controller

/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) < $article = Article::find($id); return view('edit', compact('article')); >/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) < $article = Article::find($id); $article->update($request->all()); return redirect('articles'); >
@extends('layout') @section('content') 

Редактирование статьи name >>

'patch', 'url' => ['articles/' . $article->id]]) !!> @endsection
Route::resource('articles', 'ArticlesController');

Источник

MethodNotAllowedHttpException RouteCollection.php line 218

I try to pass a value by post to post. I take the select value and send it at create file, after this the user compile other form and send it to other route post and check the validation. But it doesn’t work. Route.php

Route::get('administrator/','AdministratorController@index'); Route::get('administrator/select','AdministratorController@select'); Route::post('administrator/create','AdministratorController@create'); Route::post('administrator','AdministratorController@store'); 
public function create(Request $request)< $chapterS=SubChapters::where('ChapterName',$request->chapters)->get(); return view('administrator_pages.create',compact('chapterS','request')); > public function store(Request $request)< //dd($request->all()); $this->validate($request,['IdQuestion'=>'required']); return 'store'; > 
 1/1 MethodNotAllowedHttpException in RouteCollection.php line 218: in RouteCollection.php line 218 at RouteCollection->methodNotAllowed(array('POST')) in RouteCollection.php line 205 at RouteCollection->getRouteForMethods(object(Request), array('POST')) in RouteCollection.php line 158 at RouteCollection->match(object(Request)) in Router.php line 821 at Router->findRoute(object(Request)) in Router.php line 691 at Router->dispatchToRoute(object(Request)) in Router.php line 675 at Router->dispatch(object(Request)) in Kernel.php line 246 at Kernel->Illuminate\Foundation\Http\(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52 at Pipeline->Illuminate\Routing\(object(Request)) in CheckForMaintenanceMode.php line 44 at CheckForMaintenanceMode->handle(object(Request), object(Closure)) at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136 at Pipeline->Illuminate\Pipeline\(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32 at Pipeline->Illuminate\Routing\(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103 at Pipeline->then(object(Closure)) in Kernel.php line 132 at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99 at Kernel->handle(object(Request)) in index.php line 54 

Источник

Читайте также:  Ajax php class method
Оцените статью