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