/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store() { $advertiser = new Advertiser(); $data = Input::all(); $validator = $this->checkValidation(); if ($validator->fails()) { $messages = $validator->messages(); foreach ($messages->all() as $message) { $msg[] = $message; } return $this->errorMessage($msg); } $userDetail = $advertiser->getDetailByUserId($data['user_id']); if (empty($userDetail)) { $advertiserProfile = $advertiser->insert($data); $msg[] = "Profile saved successfully."; return $this->successMessageWithVar($msg, $advertiserProfile); } else { $advertiserProfile = $advertiser->updateData($data); $msg[] = "Profile updated successfully."; return $this->successMessageWithVar($msg, $advertiserProfile); } }
public function insert($data) { $user = new Advertiser(); if (isset($data['user_id'])) { $user->user_id = $data['user_id']; } if (isset($data['comp_name'])) { $user->comp_name = $data['comp_name']; } if (isset($data['address'])) { $user->address = $data['address']; } if (isset($data['city'])) { $user->city = $data['city']; } if (isset($data['state'])) { $user->state = $data['state']; } if (isset($data['zip'])) { $user->zip = $data['zip']; } if (isset($data['lat'])) { $user->lat = $data['lat']; } if (isset($data['lng'])) { $user->lng = $data['lng']; } if (isset($data['phone'])) { $user->phone = $data['phone']; } if (isset($data['email'])) { $user->email = $data['email']; } $user->save(); return $user; }