repository = $appclient; parent::__construct(); } /** * Display a list of appclient. * * @return Response */ public function index(AppclientRequest $request) { if ($request->wantsJson()) { return $this->getJson($request); } $this ->theme->prependTitle(trans('client::appclient.names')); return $this->theme->of('client::admin.appclient.index')->render(); } /** * Display a list of appclient. * * @return Response */ public function getJson(AppclientRequest $request) { $pageLimit = $request->input('pageLimit'); $appclients = $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->setPresenter('\\Assetdocs\\Client\\Repositories\\Presenter\\AppclientListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate($pageLimit); $appclients['recordsTotal'] = $appclients['meta']['pagination']['total']; $appclients['recordsFiltered'] = $appclients['meta']['pagination']['total']; $appclients['request'] = $request->all(); return response()->json($appclients, 200); } /** * Display appclient. * * @param Request $request * @param Model $appclient * * @return Response */ public function show(AppclientRequest $request, Appclient $appclient) { if (!$appclient->exists) { return response()->view('client::admin.appclient.new', compact('appclient')); } Form::populate($appclient); return response()->view('client::admin.appclient.show', compact('appclient')); } /** * Show the form for creating a new appclient. * * @param Request $request * * @return Response */ public function create(AppclientRequest $request) { $appclient = $this->repository->newInstance([]); Form::populate($appclient); return response()->view('client::admin.appclient.create', compact('appclient')); } /** * Create new appclient. * * @param Request $request * * @return Response */ public function store(AppclientRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $appclient = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('client::appclient.name')]), 'code' => 204, 'redirect' => trans_url('/admin/client/appclient/'.$appclient->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show appclient for editing. * * @param Request $request * @param Model $appclient * * @return Response */ public function edit(AppclientRequest $request, Appclient $appclient) { Form::populate($appclient); return response()->view('client::admin.appclient.edit', compact('appclient')); } /** * Update the appclient. * * @param Request $request * @param Model $appclient * * @return Response */ public function update(AppclientRequest $request, Appclient $appclient) { try { $attributes = $request->all(); $appclient->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('client::appclient.name')]), 'code' => 204, 'redirect' => trans_url('/admin/client/appclient/'.$appclient->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/client/appclient/'.$appclient->getRouteKey()), ], 400); } } /** * Remove the appclient. * * @param Model $appclient * * @return Response */ public function destroy(AppclientRequest $request, Appclient $appclient) { try { $t = $appclient->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('client::appclient.name')]), 'code' => 202, 'redirect' => trans_url('/admin/client/appclient/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/client/appclient/'.$appclient->getRouteKey()), ], 400); } } }