private function applyPermissions($user, $data) { $user->actions()->delete(); $keys = array_keys($data); foreach ($keys as $key) { if (starts_with($key, 'action_')) { $userAction = new UserAction(); $userAction->user_id = $user->id; $userAction->action_id = substr(strrchr($key, "_"), 1); //the number following the prefix $userAction->save(); } } }
public function assignAction(Action $action) { if ($action != null) { return UserAction::firstOrCreate(['user_id' => $this->id, 'action_id' => $action->id]); } else { Log::debug(__METHOD__ . ' *** null action given'); } }