I have a modal form in a page pointing to a route that includes an message to a client, and it does all right, but when it is going back to the page I got the message of wrong method :
The GET method is not supported for this route. Supported methods: POST
The form is :
<form action="{{route('incluir_mensagem')}}" method="post">
@csrf
<div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header cab-msg">
<h5 class="modal-title" id="staticBackdropLabel">Nova mensagem para : {{$necps->nome_part}}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="texto-oferta">Oferta : {{$ofps->desc_of}}</div>
<div class="texto-necessidade">Necessidade : {{$necps->desc_nec}}</div>
<br>
<textarea name ="mensagem" class="form-control" id="mensagem" rows="3"></textarea>
<input value="{{$ofps->id_part}}" name="id_part_t" id="id_part_t" type="hidden">
<input value="{{$ofps->id_of_part}}" name="id_of_part_t" id="id_of_part_t" type="hidden">
<input value="{{$necps->id_nec_part}}" name="id_nec_part_t" id="id_nec_part_t" type="hidden">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-bs-dismiss="modal">Sair</button>
<button type="submit" class="btn btn-primary">Enviar</button>
</div>
</div>
</div>
</div>
</form>
The route is :
Route::post('incluir_mens_trans', [TransacoesController::class,'incluir_mens_trans'])->name('incluir_mensagem');
and the controller is :
public function incluir_mens_trans(Request $request){
$confere = DB::table('transacoes')->where('id_nec_part', request('id_nec_part_t'))
->where('id_of_part', request('id_of_part_t'))
->first();
if(!$confere) {
$trans = DB::table('transacoes')->insertGetId([
'id_nec_part' => request('id_nec_part_t'),
'id_of_part' => request('id_of_part_t'),
/*Em andamento */
'id_st_trans' => 2,
'data_inic' => date('Y-m-d H:i:s')
]);
$id_trans = $trans;
}else{
$id_trans = $confere->id;
}
$msgs_i = DB::table('mensagens_trans')->insert([
'id_trans' => $id_trans,
'mensagem' => request('mensagem'),
'data' => date('Y-m-d H:i:s')
]);
$msgs = DB::table('mensagens_trans')->where('id_trans', $id_trans)
->select('mensagens_trans.*')
->orderBy('data','desc')
->paginate(5);
return back();
Some tip about what is going on? Thanks!
CodePudding user response:
you should just write the method variable as uppercase:
method="POST" replace this:
<form action="{{route('incluir_mensagem')}}" method="post">
with this
<form action="{{route('incluir_mensagem')}}" method="POST">
CodePudding user response:
Try to change :
return back();
By :
return redirect()->back();