当我进入将数据添加到系统的屏幕时,出现错误消息此路由不支持GET方法。支持的方法:POST。我无法解决。想法是在一个屏幕上输入数据,然后在另一个屏幕上输入数据,但是由于上述错误,该数据不起作用。你能帮我吗?
Route::get('/lista',[
'uses'=>'CarController@show',
'as'=>'cars.show'
]);
Route::post('/crear',[
'uses'=>'CarController@create',
'as'=>'cars.create'
]);
public function show(){
$cars=Car::all();
return view ('lista',['cars'=>$cars]);
}
public function crear(Request $request){
$patente=$request['patente'];
$marca=$request['marca'];
$modelo=$request['modelo'];
$color=$request['color'];
$fecha_ingreso=$request['fecha_ingreso'];
$car=new Car();
$car->patente=$patente;
$car->marca=$marca;
$car->modelo=$modelo;
$car->color=$color;
$car->fecha_ingreso=$fecha_ingreso;
$car->save();
return redirect()->back();
}
要创建的简要表格
<div class="col-md-6"></div>
<form action="{{route('cars.crear')}}" method="post">
@csrf
<div class="row form-group">
<div class="col-md-12">
<label for="">Patente:</label>
<input type="text" name="patente" size="6" maxlength="6" class="form-control" required>
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label for="">Marca:</label>
<input type="text" name="marca" class="form-control" required>
</div>
</div>
要显示的表格
表,td {
border: 4px solid black;
}
</style>
<div class="col-md-6">
<caption>Lista de autos</caption>
<table class="table table-striped table-hover">
<tr>
<th>Patente</th>
<th>Marca</th>
<th>Modelo</th>
<th>Color</th>
<th>Fecha_ingreso</th>
</tr>
@foreach($cars as $car)
<tr>
<td>{{$car->patente}}</td>
<td>{{$car->marca}}</td>
<td>{{$car->modelo}}</td>
<td>{{$car->color}}</td>
<td>{{$car->fecha_ingreso}}</td>
<td>
<a href="{{ route('cars.edit', $car->id )}}" class="btn btn-warning btn-xs">Modificar</a>
</td>
<td>
<form action="{{ route('cars.destroy', $car->id )}}" method="POST">
<input name="_method" type="hidden" value="DELETE">
{{ csrf_field() }}
<input type="submit" class="btn btn-danger btn-xs" value=Eliminar>
</form>
</td>
</tr>
@endforeach
</table>
</div>
答案 0 :(得分:0)
确保您的表单是用POST定义的,如下所示:
<form action="/action_page.php" method="post">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>
答案 1 :(得分:0)
似乎您正在创建get请求,并做了类似的事情
Route::match(['get', 'post'], '/clear','uses'=>'CarController@create','as'=>'cars.create' );
或
Route::any('/clear','uses'=>'CarController@create','as'=>'cars.create' );
如果您要使用表单创建发布请求,
<form action="/clear" method="post">
...
<input type="submit" value="Submit">
</form>