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