如何更新laravel

时间:2016-10-11 14:41:56

标签: updates laravel-5.3

我是Laravel的新手,我正在尝试创建一个应用程序。我创建了一个表单,并使用控制器将此表单存储到我的数据库中。表单有一个名为“Status”的下拉字段。

“状态”就像“类别”,所以我需要更改它而不更改任何其他内容。我正在尝试编写代码,但我做错了。您可以在下面看到我的代码:

控制器:

public function show($id)
    {
        $servicedevice = DeviceService::findOrFail($id);

        return view('device_service.show', compact('servicedevice', $servicedevice));
    }       

public function devicestatus(Request $request)
        {
          $devstat = DeviceService::FindOrFail($servicedevice->id);
          $devstat->status_id = $request->device_id;
          $devstat->save();

          return back();
        }

查看:

            {!! Form::open(['action' => 'DeviceServiceController@devicestatus']) !!}
            {!! Form::select('status_id', $statuslist, null, [
                'class' => 'js-example-basic-single',
                'style' => 'width:50%'
                ]) !!}
            {!! Form::hidden('id', $servicedevice->id) !!}
            {!! Form::submit('ok', ['class' => 'btn btn-sm btn-flat btn-warning']) !!}
            {!! Form::close(); !!}

路线:

Route::get('/devicestatus', 'DeviceServiceController@devicestatus');

当我尝试更改“状态”时,返回以下错误

MethodNotAllowedHttpException in RouteCollection.php line 218:

in RouteCollection.php line 218
at RouteCollection->methodNotAllowed(array('GET', 'HEAD')) in RouteCollection.php line 205
at RouteCollection->getRouteForMethods(object(Request), array('GET', 'HEAD')) in RouteCollection.php line 158
at RouteCollection->match(object(Request)) in Router.php line 780
at Router->findRoute(object(Request)) in Router.php line 610
at Router->dispatchToRoute(object(Request)) in Router.php line 596
at Router->dispatch(object(Request)) in Kernel.php line 267
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 54

你能帮我吗?

1 个答案:

答案 0 :(得分:0)

错误消息和堆栈跟踪可以准确地告诉您发生了什么:

MethodNotAllowedHttpException
...
RouteCollection->methodNotAllowed(array('GET', 'HEAD'))

您正在提交表单(默认情况下为POST方法)但您只能将路由定义为Route::get

您需要将其更改为Route::any或将第二条路线Route::post定义为同一网址,但使用不同的方法调用。