gpt4 book ai didi

Laravel 5.2 MethodNotAllowedHttpException 无法发布数据

转载 作者:行者123 更新时间:2023-12-02 04:43:17 26 4
gpt4 key购买 nike

我似乎无法在/cars/{id?}/modify 中发布数据

错误:

in RouteCollection.php line 219 at RouteCollection->methodNotAllowed(array('POST')) in RouteCollection.php line 206
at RouteCollection->getRouteForMethods(object(Request), array('POST')) in RouteCollection.php line 158

路线:

Route::get('/', 'PagesController@home');
Route::get('/about', 'PagesController@about');
Route::get('/contact', 'PagesController@contact');
Route::get('/cars', 'CarsController@index');

Route::get('/cars/{id?}/edit', 'CarsController@edit');
Route::post('/cars/{id?}/modify', 'CarsController@update');

Route::get('/cars/add', 'CarsController@add');
Route::post('/cars/add', 'CarsController@store');

Route::get('/cars/{id?}/delete','CarsController@destroy');

html:

    <form class="form-horizontal" method="post" action="/cars/{{ $car->id }}/modify">
<input type="hidden" name="_token" value="{!! csrf_token() !!}">
<input name="_method" type="hidden" value="UPDATE">
<input type="text" id="color_id" name="color_id" value="{!! $car->color_id !!}">
<fieldset>
<legend>Edit Car Information</legend>
<div class="form-group">
<label for="title" class="col-lg-2 control-label">Car Name</label>
<div class="col-lg-10">
<input type="text" value="{{ $car->name }}" class="form-control" id="name" placeholder="Car Name">
</div>
</div>
<div class="form-group">
<label for="title" class="col-lg-2 control-label">Car Color</label>
<div class="col-lg-10">
<div class="btn-group" data-toggle="buttons">
<label id="opt1" class="btn btn-primary">
<input type="radio" name="color" id="option1" autocomplete="off"> Red
</label>
<label id="opt2" class="btn btn-primary">
<input type="radio" name="color" id="option2" autocomplete="off"> Blue
</label>
<label id="opt3" class="btn btn-primary">
<input type="radio" name="color" id="option3" autocomplete="off"> Yellow
</label>
<label id="opt4" class="btn btn-primary">
<input type="radio" name="color" id="option4" autocomplete="off"> Green
</label>
<label id="opt5" class="btn btn-primary">
<input type="radio" name="color" id="option5" autocomplete="off"> Black
</label>
<label id="opt6" class="btn btn-primary">
<input type="radio" name="color" id="option6" autocomplete="off"> White
</label>
</div>
</div>
</div>

<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button class="btn btn-default">Cancel</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
</form>

最佳答案

laravel 中没有更新方法/路由之类的东西。对于编辑,您应该使用 PUT


您可以通过改变两件事来解决您的问题:

您的路由方法

Route::post('/cars/{id?}/modify', 'CarsController@update');

Route::put('/cars/{id?}/modify', 'CarsController@update');

在你的表单中

<input name="_method" type="hidden" value="UPDATE">

<input name="_method" type="hidden" value="PUT">

关于Laravel 5.2 MethodNotAllowedHttpException 无法发布数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35569142/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com