download1002 2018-06-09 07:43
浏览 285

如何在Laravel中一键更新MySql数据库值

I am creating a web site. So , there is a table to show users. In my database, I stored 0 for the Pending and 1 for the Approved under Action column. If some user has 0 , Pending will be displayed in this table and if the user has 1 Approved will be displayed. Now I want to when someone clicks this Pending button, I want to update database value to 1. I tried it as below. But , when I click Pending button, it gives me this error -

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message

And also I was unable to update the database value.

How Can I Fix this ??

View Page ( AdminPanel.blade.php )

 <table class="table table-bordered">

            <tr>
                <td> Action</td>
            </tr>

            @foreach($data as $value )
                <tr>
                    @if($value->action ==0)
                        <td><a href="actionedit/{{ $value->id }}"><input type="submit" name="pending" value="Pending"
                                                                         class="btn btn-warning"></a></td>
                    @else
                        <td><a href="edit/{{ $value->id }}"><input type="submit" name="update" value="Approved"
                                                                   class="btn btn-success"></a></td>
                    @endif
                </tr>
            @endforeach
        </table>

Controller. ( AdminPanelController.php )

public function actionedit(Request $request)
    {
        // Add Validation

        DB::table('users')
            ->update(['action' => 1]);

            $request->session()->flash('Msg', 'Successfully Updated !!');

            return redirect('adminPanel');

    }

Route.

Route::put('/actionedit/{id}', 'AdminPanelController@actionedit');
  • 写回答

1条回答 默认 最新

  • drogon982007 2018-06-09 08:04
    关注

    You are requesting get not put change it to get http verb

    Route::get('/actionedit/{id}', 'AdminPanelController@actionedit');
    

    or use ajax to request as post or put

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!