I am sending values from view to controller
Here is my Script :
<script>
$(document).ready(function() {
var vehicle_data = [];
$("#vehicle_submit").click(function(event) {
event.preventDefault();
vehicle_data.push($("#_token").val());
vehicle_data.push($("#VehicleNo").val());
vehicle_data.push($("#VehicleName").val());
$.ajax({
type: "POST",
url: "{{ URL::to('vehicle-process') }}",
data: "vehicle_arr=" + vehicle_data,
async: true,
success: function(data) {
console.log(data);
}
}, "json");
});
});
</script>
I am sending the values VehicleNo and VehicleName to the vehicle-process
controller as a single array named as vehicle_arr using POST Method.
Now in the controller :
public function vehicle_process()
{
$a = Input::except(array('_token')) ;
$rule = array(
'VehicleNo' => 'required',
'VehicleSeats' => 'required'
);
$validator = Validator::make($a, $rule);
if ($validator - > fails()) {
$messages = $validator - > messages();
return $messages;
}
else
{
$table = new VehicleModel;
$table->VehicleNo=$VehicleNo; // How can i get the value of VehicleNo and Vehcle Name
$table->save();
}
The Validator can't able to analyze the name of the element i.e., VehicleNo or VehicleSeats,
So whenever i pass the data from view it was showing VeihcleNo required validator messages all the time.
Can i make the validator like
$rule = array(
$a['VehicleNo'] => 'required',
$a['VehicleSeats'] => 'required'
);
as i am storing the all the values in $a.
I even tested return $a;
to view all elements in the controller it shows like
Object {vehicle_arr: "wBNTzuTY20GL6BR147TIM9l8mxpCbgMAM7ok7fD4,EZ-55,35"}
Is it possible to get values like
$value = Input::post('VehicleNo');
So, How can i get the values extract so that i can done with the validation and store in db
My Model just has the Table Name
So i just need the way to get the value of $VehicleNo to store in db. So that i can construct this
$table->VehicleNo=$VehicleNo;
$table->save();