<tfoot id='Dmb51'></tfoot>

    1. <i id='Dmb51'><tr id='Dmb51'><dt id='Dmb51'><q id='Dmb51'><span id='Dmb51'><b id='Dmb51'><form id='Dmb51'><ins id='Dmb51'></ins><ul id='Dmb51'></ul><sub id='Dmb51'></sub></form><legend id='Dmb51'></legend><bdo id='Dmb51'><pre id='Dmb51'><center id='Dmb51'></center></pre></bdo></b><th id='Dmb51'></th></span></q></dt></tr></i><div id='Dmb51'><tfoot id='Dmb51'></tfoot><dl id='Dmb51'><fieldset id='Dmb51'></fieldset></dl></div>
        <bdo id='Dmb51'></bdo><ul id='Dmb51'></ul>
    2. <legend id='Dmb51'><style id='Dmb51'><dir id='Dmb51'><q id='Dmb51'></q></dir></style></legend>
    3. <small id='Dmb51'></small><noframes id='Dmb51'>

    4. Laravel 控制器更新方法不起作用

      时间:2023-10-11
          <tbody id='zOm3f'></tbody>
      1. <legend id='zOm3f'><style id='zOm3f'><dir id='zOm3f'><q id='zOm3f'></q></dir></style></legend>
        <tfoot id='zOm3f'></tfoot>

        <small id='zOm3f'></small><noframes id='zOm3f'>

          <bdo id='zOm3f'></bdo><ul id='zOm3f'></ul>

          <i id='zOm3f'><tr id='zOm3f'><dt id='zOm3f'><q id='zOm3f'><span id='zOm3f'><b id='zOm3f'><form id='zOm3f'><ins id='zOm3f'></ins><ul id='zOm3f'></ul><sub id='zOm3f'></sub></form><legend id='zOm3f'></legend><bdo id='zOm3f'><pre id='zOm3f'><center id='zOm3f'></center></pre></bdo></b><th id='zOm3f'></th></span></q></dt></tr></i><div id='zOm3f'><tfoot id='zOm3f'></tfoot><dl id='zOm3f'><fieldset id='zOm3f'></fieldset></dl></div>
                本文介绍了Laravel 控制器更新方法不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我是 Laravel 的新手.

                I am new in Laravel.

                我通过作曲家php artisan generate:scaffold cityway/generator和它的索引页(创建和存储方法)制作了控制器、模型和视图,但我工作得很好不知道 update 方法有什么问题.

                I made controller, Model and views by way/generator by composer php artisan generate:scaffold cities and Its index page (Create and store method) Working well but I don't know what is the problem with update method.

                这是我的 CitiesController 方法(更新):

                This is my CitiesController method(Update):

                public function update($id)
                {
                    $city = City::findOrFail($id);
                
                    $validator = Validator::make($data = Input::all(), City::$rules);
                
                    if ($validator->fails())
                    {
                        return Redirect::back()->withErrors($validator)->withInput();
                    }
                
                    $city->update($data);
                    return Redirect::route('admin.cities.index');
                }
                

                这是我的模型(城市):

                class City extends Eloquent {
                   protected $primaryKey='city_id';
                
                    public static $rules = [
                         'name'     => 'required',
                         'image'     => 'mimes:jpeg',
                         'parent_id' => 'required',
                         'name'      => 'required',
                         'english_name'=>'unique:cities,english_name|required'
                
                    ];
                    protected $fillable = ['name', 'parent_id', 'english_name','population','phone_prefix','image'];
                }
                

                这是我的观点(编辑):

                <ul>
                    {{ Form::model($city,array('route'=>array('admin.cities.update',$city->id),'method'=>'PUT','files'=>true)) }}
                    <!--Here I included my form-->
                    @include('admin.forms._partial.formcity')
                    <li>
                        {{ Form::submit('submit') }}
                    </li>
                    {{ Form::close() }}
                </ul>
                

                这是我的路线:

                Route::group(array('prefix'=>'admin','before'=>'Auth'),function(){
                    Route::resource('cities', 'CitiesController');
                });
                

                当我点击提交按钮 Laravel 抛出这个错误:

                When I click on submit button Laravel throwout this error:

                SymfonyComponentHttpKernelExceptionMethodNotAllowedHttpException

                Symfony Component HttpKernel Exception MethodNotAllowedHttpException

                注意:我的观点很有效.我认为问题出在控制器方法上,该控制器的其他方法如 createstore 也可以正常工作.

                note:My view works well. I think the problem is from controller method, and other methods of this controller like create and store works well too.

                推荐答案

                在你的模型中你有 protected $primaryKey='city_id'; 但在你看来你有:

                In your model you have protected $primaryKey='city_id'; but in your view you have:

                {{ Form::model($city,array('route'=>array('admin.cities.update',$city->id),'method'=>'PUT','files'=>true)) }}
                

                我的意思是 $city->id 应该是 $city->city_id

                I mean $city->id should be $city->city_id

                这篇关于Laravel 控制器更新方法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:从控制器 CakePHP 3.x 执行 shell 下一篇:如何将基于页面的 PHP 应用程序转换为 MVC?

                相关文章

                  <tfoot id='MLkFR'></tfoot>

                  <legend id='MLkFR'><style id='MLkFR'><dir id='MLkFR'><q id='MLkFR'></q></dir></style></legend>
                    <bdo id='MLkFR'></bdo><ul id='MLkFR'></ul>
                  <i id='MLkFR'><tr id='MLkFR'><dt id='MLkFR'><q id='MLkFR'><span id='MLkFR'><b id='MLkFR'><form id='MLkFR'><ins id='MLkFR'></ins><ul id='MLkFR'></ul><sub id='MLkFR'></sub></form><legend id='MLkFR'></legend><bdo id='MLkFR'><pre id='MLkFR'><center id='MLkFR'></center></pre></bdo></b><th id='MLkFR'></th></span></q></dt></tr></i><div id='MLkFR'><tfoot id='MLkFR'></tfoot><dl id='MLkFR'><fieldset id='MLkFR'></fieldset></dl></div>

                    <small id='MLkFR'></small><noframes id='MLkFR'>