【问题标题】:"MethodNotAllowedHttpException" retuned from Laravel 5.2 update从 Laravel 5.2 更新重新调整的“MethodNotAllowedHttpException”
【发布时间】:2016-09-18 20:52:16
【问题描述】:

在 Laravel 5.2 中更新表单时,我正在重新调整 MethodNotAllowedHttpException。我知道 put 方法可能存在问题。

从索引发送的表单:

{!! Form::model('Customers', ['route'=>['products.update', Auth::user()->id]]) !!}

{{ Form::hidden('business', Auth::user()->name, array('class' => 'form-control', 'required' => '','maxlength'=>'255'))}}


{{ Form::label('post', 'Mailbox')}}
{{ Form::checkbox('post',1, null, array('class' => 'form-control'))}}

控制器是:

  public function update(Request $request, $id)
    {
       $this->validate($request, array (
            'post' => '',
            'mailbox' => '',
            'conum' => '',
            'prefix' => '',
            'telans' => '',
            'TC' => 'required',

        ));

        //store
        $post = Customers::find($id);



        $post->post = $request->input('post');
        $post->postpro = $request->input('mailbox');
        $post->telans = $request->input('telans');
        $post->conum = $request->input('conum');
        $post->prefix = $request->inut('prefix');
        $post->tc = $request->input('TC');

        //save
        $post->save();

        //session flash message
        //Session::flash('success','This customer has now been added');

        //redirect
return redirect('/home');}

路线如下:

  Route::resource('products', 'ProductsController');

谢谢

【问题讨论】:

  • 您是否在 IIS 服务器上运行?
  • 在 Mamp 和 Apache 上运行
  • 运行php artisan route:list 命令并检查products.update 是否在列表中。
  • 它在列表中。方法是 PUT @AlexeyMezenin
  • 表单是否生成put表单?

标签: php laravel laravel-5.2


【解决方案1】:

你忘记了引号,替换这个:

PHP

$post->post = $request->input(post);

有了这个:

$post->post = $request->input('post');

不要忘记将 _method 设置为 put。

【讨论】:

  • {!! Form::model('Customers', ['route'=>['products.update', Auth::user()->id],'method' => 'PUT']) !!} 已添加。现在您更改的错误是:从空值创建默认对象
  • 这样有效吗?提出报价应该解决错误:ProductsController.php 第 126 行中的ErrorException:使用未定义的常量后 - 假定为“后”
  • 我现在收到错误:从空值创建默认对象
  • 这是另一个错误 :) 你能编辑你的帖子并向我们展示你的整个功能更新吗,我会尝试修复错误:)
  • 谢谢!我已经把它加到上面了
猜你喜欢
  • 2016-07-30
  • 2019-01-16
  • 2016-08-31
  • 2018-01-13
  • 1970-01-01
  • 2017-11-14
  • 1970-01-01
  • 2023-03-31
  • 1970-01-01
相关资源
最近更新 更多