public function markAcceptance($policyCode, $userUid) { // get inputs // $policy = Policy::where('policy_code', '=', $policyCode)->first(); $user = User::getIndex($userUid); $acceptFlag = Input::has('accept_flag'); // check inputs // if (!$user || !$policy || !$acceptFlag) { return Response::make('Invalid input.', 404); } // check privileges // if (!$user->isAdmin() && $user->user_uid != Session::get('user_uid')) { return Response::make('Insufficient privileges to mark policy acceptance.', 401); } // get or create new user policy // $userPolicy = UserPolicy::where('user_uid', '=', $userUid)->where('policy_code', '=', $policyCode)->first(); if (!$userPolicy) { $userPolicy = new UserPolicy(array('user_policy_uid' => GUID::create(), 'user_uid' => $userUid, 'policy_code' => $policyCode)); } $userPolicy->accept_flag = $acceptFlag; $userPolicy->save(); return $userPolicy; }
public function getPolicyAttribute() { $policy = Policy::where('policy_code', '=', $this->policy_code)->first(); return $policy ? $policy->policy : ''; }
public function getByCode($policyCode) { return Policy::where('policy_code', '=', $policyCode)->first(); }