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