public function store() { // Transaction strats here because we are connecting three tables \DB::beginTransaction(); //User credintial information $username = \Input::get('branch_code'); $password = str_random(10); $p_email = \Input::get('p_email'); $s_contact_person = \Input::get('s_contact_person'); $hashPassword = \Hash::make($password); //Insert user credentials $uId = \User::insertGetId(array('username' => $username, 'password' => $hashPassword, 'email' => $p_email, 'profilesId' => 2, 'active' => 'Y', 'displayname' => $s_contact_person)); if (!$uId) { \DB::rollback(); return \Redirect::back()->with('error', 'Failed to save'); } $branch_name = \Input::get('branch_name'); $branch_code = \Input::get('branch_code'); $branch_address = \Input::get('branch_address'); $branch_city = \Input::get('branch_city'); $branch_state = \Input::get('branch_state'); $branch_pin = \Input::get('branch_pin'); $branch_land_line = \Input::get('branch_land_line'); $branch_alt_land_line = \Input::get('branch_alt_land_line'); $branch_fax = \Input::get('branch_fax'); // Insert Branch into table $branchId = \Branch::insertGetId(array('branch_name' => $branch_name, 'branch_code' => $branch_code, 'branch_address' => $branch_address, 'branch_city' => $branch_city, 'branch_state' => $branch_state, 'branch_pin' => $branch_pin, 'branch_land_line' => $branch_land_line, 'branch_alt_land_line' => $branch_alt_land_line, 'branch_fax' => $branch_fax, 'user_id' => $uId)); if (!$branchId) { \DB::callback(); return \Redirect::back()->with('error', 'Failed to save'); } // Branch contact information $branch_head = \Input::get('branch_head'); $p_mobile_no = \Input::get('p_mobile_no'); $p_alt_mobile_no = \Input::get('p_alt_mobile_no'); $p_email = \Input::get('p_email'); $p_alt_email = \Input::get('p_alt_email'); $s_mobile_no = \Input::get('s_mobile_no'); $s_alt_mobile_no = \Input::get('s_alt_mobile_no'); $s_email = \Input::get('s_email'); $s_alt_email = \Input::get('s_alt_email'); //Insert Data to contact table $contactId = \BranchContact::insertGetId(array('branch_head' => $branch_head, 'p_mobile_no' => $p_mobile_no, 'p_alt_mobile_no' => $p_alt_mobile_no, 'p_email' => $p_email, 'p_alt_email' => $p_alt_email, 's_contact_person' => $s_contact_person, 's_mobile_no' => $s_mobile_no, 's_alt_mobile_no' => $s_alt_mobile_no, 's_email' => $s_email, 's_alt_email' => $s_alt_email, 'user_id' => $uId, 'branch_id' => $branchId)); if (!$contactId) { \DB::rollback(); return \Redirect::back()->with('error', 'Failed to add'); } elseif ($contactId) { \DB::commit(); \Mail::send('emails.user_credential', array('name' => $s_contact_person, 'username' => $username, 'password' => $password), function ($message) use($p_email, $username) { $message->to($p_email, $username)->subject('User Credential'); }); return \Redirect::back()->with('success', 'Successfully added'); } print_r(\Input::all()); }
<?php function callsay($arg1, $arg2) { echo $arg2 * $arg1; } class DB { public $ab = 1; public function callecho($arg1, $arg2) { echo $arg2 + $arg1; } public function callback() { call_user_func_array(array('callsay'), array('1', '2')); } } $db = new DB(); $db->callback(); // echo $db->ab;
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update3($id) { // Transaction begins here \DB::beginTransaction(); //user data $displayname = \Input::get('displayname'); //call user model $user = \User::find($id); $user->displayname = $displayname; //update if (!$user->save()) { \DB::callback(); return \Redirect::back()->with('error', 'Failed to update'); } //user contact detail $mobile = \Input::get('mobile'); $alt_mobile = \Input::get('alt_mobile'); $alt_email = \Input::get('alt_email'); //call user contact model $contact = \UserContact::firstOrCreate(array('user_id' => $id)); $contact->mobile = $mobile; $contact->alt_mobile = $alt_mobile; $contact->alt_email = $alt_email; // update table if (!$contact->save()) { \DB::callback(); return \Redirect::back()->with('error', 'Failed to update'); } //Company detail $company_name = \Input::get('company_name'); $company_address = \Input::get('company_address'); $company_city = \Input::get('company_city'); $company_state = \Input::get('company_state'); $company_pin = \Input::get('company_pin'); $company_land_line = \Input::get('company_land_line'); $company_alt_land_line = \Input::get('company_alt_land_line'); $company_fax = \Input::get('company_fax'); $company_website = \Input::get('company_website'); //call company model $company = \Company::firstOrCreate(array('user_id' => $id)); $company->company_name = $company_name; $company->company_address = $company_address; $company->company_city = $company_city; $company->company_state = $company_state; $company->company_pin = $company_pin; $company->company_phone = $company_land_line; $company->company_alt_phone = $company_alt_land_line; $company->company_fax = $company_fax; $company->company_website = $company_website; // update table if (!$company->save()) { \DB::rollback(); return \Redirect::back()->with('error', 'Failed to update'); } else { \DB::commit(); return \Redirect::route('branch.client.index')->with('success', 'Successfully updated'); } }