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