方法不允许,但正在重新使用代码
Method not allowed but code is being re used
我正在尝试从我已经定义了所有路由的控制器调用更新方法(一旦我定义了他们的路由之一,我可以用资源定义路由吗?,我收到一个错误...)我自己,但我知道我收到了一个错误,即使我在其他工作路线和视图中使用相同的代码也是如此。
你能帮我找出错误吗?
提前致谢。
路线(所有其他路线都正常但更新)。
Route::get('notas/notasGet/', 'NotasController@notasGet')->name('notas.notasGet');
Route::post('notas/notasPost/', 'NotasController@notasPost')->name('notas.notasPost');
Route::get('notas/create/', 'NotasController@create')->name('notas.create');
Route::get('notas/store/', 'NotasController@store')->name('notas.store');
Route::post('notas/update/{id}', 'NotasController@update')->name('notas.update');
其实我没有成功的参数,但假设它会在调用完成后出现。
控制器(典型资源)
public function update(Request $request, Nota $nota)
{
//
}
景色
<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3 border-bottom">
<h1 class="h5">Nota de venta</h1>
<div class="btn-toolbar mb-2 mb-md-0">
<div class="btn-group mr-2">
<button class="btn btn-sm btn-outline-secondary">Exportar</button>
</div>
</div>
</div>
<div class="border-bottom">
<div class="col-md-8 order-md-1 ">
<form method="post" action="{{ route('notas.update',[$nota->idNota]) }}">
{{ csrf_field() }}
<input type="hidden" name="_method" value="PUT">
<div class="checkbox mb-3">
<label>
<input type="checkbox" value="true"> Pagada
</label>
</div>
<div class="col-md-12">
<label for="usuario">Usuario</label>
<select class="custom-select d-block w-100" id="usuario">
<option value="">Selecciona...</option>
<option>United States</option>
</select>
<div class="invalid-feedback">
Please select a valid country.
</div>
</div>
<p>
<div class="form-group">
<label for="strNota">Comentarios</label>
<textarea class="form-control" rows="3" id="strNota" name="text"></textarea>
</div>
</p>
<p>
<hr class="mb-4">
<div >
<button type="submit" class="btn btn-primary" id="submitForm">Guardar cambios <br> en la venta</button>
</div>
</p>
</form>
</div>
</div>
对更新的调用来自对创建的调用,我post这里的代码,是同一个控制器的一部分。
public function create()
{
//
$lockers = null;
$lockers = Locker::all();
$eventos = null;
$eventos = Evento::all();
$cajaAbierta = Caja::whereRaw('dtmCorte IS NULL')->get()->first();
$currentTime = Carbon::now('-5:00');
$cargos = null;
$cargos = Cargo::all();
$productos = ProductoServicioEvento::all();
if($cajaAbierta)
{
$nota = Nota::create(
[
'idCaja'=>$cajaAbierta->idCaja,
'idRealiza'=>$cajaAbierta->idUsuario,
'dtmHoraCargo'=>$currentTime,
]
);
if($nota)
{
// return redirect()->route('grupos.index')->with('success','Grupo creado con éxito');
return view('notas.create',['lockers'=>$lockers,'eventos'=>$eventos,'nota'=>$nota, 'cargos'=>$cargos,'productos'=>$productos]);
}
}
}
导航器中的测试,当我单击按钮时 "Guardar cambios en la venta"。
错误。
您已在此处将 Method
更改为 PUT
<input type="hidden" name="_method" value="PUT">
但是您在此处将 Route
定义为 POST
Route::post('notas/update/{id}', 'NotasController@update')->name('notas.update');
这就是
的原因
Method Not Allowed Here Exception
只需将您的路线更改为 PUT
Route::put('notas/update/{id}', 'NotasController@update')->name('notas.update');
我正在尝试从我已经定义了所有路由的控制器调用更新方法(一旦我定义了他们的路由之一,我可以用资源定义路由吗?,我收到一个错误...)我自己,但我知道我收到了一个错误,即使我在其他工作路线和视图中使用相同的代码也是如此。 你能帮我找出错误吗? 提前致谢。
路线(所有其他路线都正常但更新)。
Route::get('notas/notasGet/', 'NotasController@notasGet')->name('notas.notasGet');
Route::post('notas/notasPost/', 'NotasController@notasPost')->name('notas.notasPost');
Route::get('notas/create/', 'NotasController@create')->name('notas.create');
Route::get('notas/store/', 'NotasController@store')->name('notas.store');
Route::post('notas/update/{id}', 'NotasController@update')->name('notas.update');
其实我没有成功的参数,但假设它会在调用完成后出现。
控制器(典型资源)
public function update(Request $request, Nota $nota)
{
//
}
景色
<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3 border-bottom">
<h1 class="h5">Nota de venta</h1>
<div class="btn-toolbar mb-2 mb-md-0">
<div class="btn-group mr-2">
<button class="btn btn-sm btn-outline-secondary">Exportar</button>
</div>
</div>
</div>
<div class="border-bottom">
<div class="col-md-8 order-md-1 ">
<form method="post" action="{{ route('notas.update',[$nota->idNota]) }}">
{{ csrf_field() }}
<input type="hidden" name="_method" value="PUT">
<div class="checkbox mb-3">
<label>
<input type="checkbox" value="true"> Pagada
</label>
</div>
<div class="col-md-12">
<label for="usuario">Usuario</label>
<select class="custom-select d-block w-100" id="usuario">
<option value="">Selecciona...</option>
<option>United States</option>
</select>
<div class="invalid-feedback">
Please select a valid country.
</div>
</div>
<p>
<div class="form-group">
<label for="strNota">Comentarios</label>
<textarea class="form-control" rows="3" id="strNota" name="text"></textarea>
</div>
</p>
<p>
<hr class="mb-4">
<div >
<button type="submit" class="btn btn-primary" id="submitForm">Guardar cambios <br> en la venta</button>
</div>
</p>
</form>
</div>
</div>
对更新的调用来自对创建的调用,我post这里的代码,是同一个控制器的一部分。
public function create()
{
//
$lockers = null;
$lockers = Locker::all();
$eventos = null;
$eventos = Evento::all();
$cajaAbierta = Caja::whereRaw('dtmCorte IS NULL')->get()->first();
$currentTime = Carbon::now('-5:00');
$cargos = null;
$cargos = Cargo::all();
$productos = ProductoServicioEvento::all();
if($cajaAbierta)
{
$nota = Nota::create(
[
'idCaja'=>$cajaAbierta->idCaja,
'idRealiza'=>$cajaAbierta->idUsuario,
'dtmHoraCargo'=>$currentTime,
]
);
if($nota)
{
// return redirect()->route('grupos.index')->with('success','Grupo creado con éxito');
return view('notas.create',['lockers'=>$lockers,'eventos'=>$eventos,'nota'=>$nota, 'cargos'=>$cargos,'productos'=>$productos]);
}
}
}
导航器中的测试,当我单击按钮时 "Guardar cambios en la venta"。
错误。
您已在此处将 Method
更改为 PUT
<input type="hidden" name="_method" value="PUT">
但是您在此处将 Route
定义为 POST
Route::post('notas/update/{id}', 'NotasController@update')->name('notas.update');
这就是
的原因Method Not Allowed Here Exception
只需将您的路线更改为 PUT
Route::put('notas/update/{id}', 'NotasController@update')->name('notas.update');