I have a modal with a form and when I give the button to save the data I have entered, it does not send me to the address / path that is defined in the action attribute of the form tag, and therefore it does not save data In the database, what would I have to do to send the data to the controller? Here the modal form:
<div class="modal fade modal-slide-in-right" aria-hidden="true" role="dialog"
tabindex="-1" id="comentario-{{$lib->lib_no}}" >
<form class="form-horizontal" method="POST" action="{{ route('comenta.store') }}">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">x</span>
</button>
<h4 class="modal-title">Nuevo Comentario</h4>
</div>
<div class="modal-body">
<input type="hidden" name="_token" value="{{csrf_token()}}">
<label for="cmt_titulo">Título</label>
<input type="text" name="cmt_titulo" placeholder="Título...">
<br>
<label for="cmt_texto">Escribe tu comentario</label>
<br>
<textarea cols="50" rows="10" name="cmt_texto" placeholder="Escribe tu comentario..."></textarea>
<br>
<input type="hidden" name="cmt_libro_no" value="{{$lib->lib_no}}">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
<button type="submit" class="btn btn-primary" >Guardar</button>
</div>
</div>
</div>
</form>
and this is the controller's method:
public function store(ComentarioFormRequest $request){
$comentario= new Comentario;
$comentario->cmt_no=0;
$fecha=Carbon::now('Europe/Madrid');
$comentario->cmt_fecha=$fecha->toDateString();
$comentario->cmt_titulo=$request->get('cmt_titulo');
$comentario->cmt_texto=$request->get('cmt_texto');
$comentario->cmt_cliente_id=auth()->user()->u_cliente_id;
$comentario->cmt_libro_id=Libro::select('id_libro')->where('lib_no', $request->get('cmt_libro_no'));
$comentario->cmt_activo=1;
$comentario->save();
$comentario2=Comentario::orderBy('id_comentario', 'desc')
->first();
Comentario::where('id_comentario', $comentario2->id_comentario)
->update(['cmt_no'=>++$comentario2->id_comentario]);
return Redirect::to('cliente/comenta');
}
Nothing comes to this form request:
<?php
namespace libreir\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ComentarioFormRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'cmt_no'=> 'integer',
'cmt_fecha'=>'date',
'cmt_titulo'=>'string|required',
'cmt_texto'=>'string|required',
'msj_cliente_id'=>'integer',
'cmt_libro_id'=>'integer|required',
'cmt_activo'=>'integer|max:1|min:0'
];
}
}