/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { if ($body = \Request::input('body')) { $translation = Translation::where('body', $body)->first(); if ($translation) { $response = response()->json([['id' => $translation->getId(), 'body' => $translation->body]]); } else { $response = response()->json(['errors' => ['The translation hasn\'t found.']], 404); } } else { if ($autocomplete = \Request::input('autocomplete')) { $translations = Translation::select('body')->where('body', 'LIKE', "{$autocomplete}%")->take(\Request::header('Limit') ?: 5)->get(); if (count($translations) > 0) { $response = response()->json($translations); } else { $response = response()->json(['errors' => ['The matched translations haven\'t found.']], 404); } } else { $result = Translation::paginate(\Request::header('Limit') ?: 10); $headers['Current-Page'] = $result->currentPage(); $headers['Last-Page'] = $result->lastPage(); $translations = []; foreach ($result as $key => $item) { $translations[$key]['id'] = $item->getId(); $translations[$key]['body'] = $item->body; } if (count($translations) > 0) { $response = response()->json($translations, 200, $headers); } else { $response = response()->json(['errors' => ['there aren\'t any translations.']], 404); } } } return $response; }
public function listTranslate() { if (Auth::user()->is('admin')) { $type = 'admin'; $translate = Translation::paginate(20); } else { $type = 'user'; $translate = Translation::where('owner', Auth::user()->id)->paginate(20); } return view('translate.list', ['type' => $type, 'translates' => $translate]); }