I created a modal using Bootstrap, to add a new row into table. I don't know why and how doesn't work.
This is table_edit.blade.php MODAL:
<div id="formModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Adaugare Rolete</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<span id="form_result"></span>
<form method="post" id="sample_form" class="form-horizontal" action ="">
@csrf
<div class="form-group">
<label class="control-label col-md-4" >ProdusID : </label>
<div class="col-md">
<input type="text" name="ProdusID" id="ProdusID" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4">Denumire : </label>
<div class="col-md">
<input type="text" name="Denumire" id="Denumire" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4" >Cant1 : </label>
<div class="col-md">
<input type="text" name="Cant1" id="Cant1" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4" >Cant2 : </label>
<div class="col-md">
<input type="text" name="Cant2" id="Cant2" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4" >Cant3 : </label>
<div class="col-md">
<input type="text" name="Cant3" id="Cant3" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4" >Cant4 : </label>
<div class="col-md">
<input type="text" name="Cant4" id="Cant4" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4" >Data : </label>
<div class="col-md">
<input type="date" name="Data" id="Data" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4" >Pret Intrare : </label>
<div class="col-md">
<input type="text" name="Pret_Intrare" id="Pret_Intrare" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4" >Pret Iesire : </label>
<div class="col-md">
<input type="text" name="Pret_Iesire" id="Pret_Iesire" class="form-control" />
</div>
</div>
<br />
<div class="form-group" align="center">
<input type="hidden" name="action" id="action" value="Add" />
<input type="hidden" name="hidden_id" id="hidden_id" />
<input type="submit" name="action_button" id="action_button" class="btn btn-warning" value="Add" />
</div>
</form>
</div>
</div>
</div>
</div>
Here we can see I do an easy html bootstrap, it's oke, it's work, but affter, maybe in Controller it's the problem.
This is Controller:
public function store(Request $request){
$rules = array(
'ProdusID' => 'required',
'Denumire' => 'required',
'Cant1' => 'required',
'Cant2' => 'required',
'Cant3' => 'required',
'Cant4' => 'required',
'Data' => 'required',
'Pret_Intrare' => 'required',
'Pret_Iesire' => 'required'
);
$error = Validator::make($request->all(), $rules);
if($error->fails()){
return response()->json(['errors' => $error->errors()->all()]);
}
$form_data = array(
'ProdusID' => $request->ProdusID,
'Denumire' => $request->Denumire,
'Cant1' => $request->Cant1,
'Cant2' => $request->Cant2,
'Cant3' => $request->Cant3,
'Cant4' => $request->Cant4,
'Data' => $request->Data,
'Pret_Intrare' => $request->Pret_Intrare,
'Pret_Iesire' => $request->Pret_Iesire
);
Rolete::create($form_data);
return response()->json(['succes' => 'Data Added successfully.']);
}
And web:
Route::post('tabledit/store', 'TableditControllerRolete@store')->name('tabledit.store');
(!) UPDATE: I don't have any error, but he doesn't adding into table.
source https://stackoverflow.com/questions/70266710/why-nothing-is-inserted-in-the-table-even-if-it-is-related-to-sql-and-laravel
No comments:
Post a Comment