input('id')) { $knowledge = Knowledge::where('id', $request->input('id')) ->where('show', 1) ->first() ->toArray(); if (!$knowledge) return $this->fail([500, __('Article does not exist')]); $user = User::find($request->user()->id); $userService = new UserService(); if (!$userService->isAvailable($user)) { $this->formatAccessData($knowledge['body']); } $subscribeUrl = Helper::getSubscribeUrl($user['token']); $knowledge['body'] = str_replace('{{siteName}}', admin_setting('app_name', 'XBoard'), $knowledge['body']); $knowledge['body'] = str_replace('{{subscribeUrl}}', $subscribeUrl, $knowledge['body']); $knowledge['body'] = str_replace('{{urlEncodeSubscribeUrl}}', urlencode($subscribeUrl), $knowledge['body']); $knowledge['body'] = str_replace( '{{safeBase64SubscribeUrl}}', str_replace( array('+', '/', '='), array('-', '_', ''), base64_encode($subscribeUrl) ), $knowledge['body'] ); return $this->success($knowledge); } $builder = Knowledge::select(['id', 'category', 'title', 'updated_at']) ->where('language', $request->input('language')) ->where('show', 1) ->orderBy('sort', 'ASC'); $keyword = $request->input('keyword'); if ($keyword) { $builder = $builder->where(function ($query) use ($keyword) { $query->where('title', 'LIKE', "%{$keyword}%") ->orWhere('body', 'LIKE', "%{$keyword}%"); }); } $knowledges = $builder->get() ->groupBy('category'); return $this->success($knowledges); } private function formatAccessData(&$body) { $pattern = '/(.*?)/s'; $replacement = '
' . __('You must have a valid subscription to view content in this area') . '
'; $body = preg_replace($pattern, $replacement, $body); } }