I am fairly new to everything and I am wondering if it is possible to store declared variables in to database?
For example(these are placed in the nameoffilecontroller.php),
public function onewayflightshow()
{ $a=Session::get('children');
$b=Session::get('adult');
$c=Session::get('infant');
$d=Session::get('destinationto');
$e=Session::get('destinationfrom');
$f=Session::get('departure');
$results = DB::table('oneways')->get();
if (!empty($results))
foreach ($results as $user)
{
$adultFee = ($user->fare)*$b;
/*------------------------Child Fee------------------------*/
$partialFee1 = ($user->fare)*.05;
$partialFee2 = ($user->fare)-$partialFee1;
$childFee = $partialFee2*$a;
/*------------------------Infant Fee------------------------*/
$partialFee3 = ($user->fare)*.10;
$partialFee4 = ($user->fare)-$partialFee3;
$infantFee = $partialFee2*$c;
$payment = ($adultFee+$childFee+$infantFee);
var_dump($payment);
}
$rules = array(
'title' => 'required',
'lastname' => 'required',
'email' => 'required|email',
'cemail' => 'required|same:email',
'firstname' => 'required',
'middlename' => 'required',
'birthday' => 'required',
'city' => 'required',
'streetadd' => 'required',
'zipcode' => 'required|max:4',
'country' => 'required',
'home' => 'required|max:7',
'mobile' => 'required|max:12'
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
$messages = $validator->messages();
return View::make('content.onewayflightfillup')->withErrors($validator);
} else {
$reserve = new Reserves;
$reserve->title = Input::get('title');
$reserve->lastname = Input::get('lastname');
$reserve->firstname= Input::get('firstname');
$reserve->middlename = Input::get('middlename');
$reserve->birthday = Input::get('birthday');
$reserve->city = Input::get('city');
$reserve->streetadd = Input::get('streetadd');
$reserve->zipcode = Input::get('zipcode');
$reserve->country = Input::get('country');
$reserve->home = Input::get('home');
$reserve->work = Input::get('work');
$reserve->fax = Input::get('fax');
$reserve->mobile = Input::get('mobile');
$reserve->email = Input::get('email');
$reserve->children = Session::get('children');
$reserve->children = Session::get('adult');
$reserve->children = Session::get('infant');
$reserve->children = Session::get('destinationfrom');
$reserve->children = Session::get('destinationto');
$reserve->children = Session::get('departure');
$reserve->$payment; <-- IS THIS EVEN POSSIBLE?
$reserve->save();
var_dump($reserve);
return View::make('content.onewayflightbooklist');
}}
I am trying to save();
everything in my database, from the session variables to the inputed values from the user but the problem is I don't know how to insert $payment
into the database table. Is it even possible? If yes, what are the way/s of doing it?