repository = $advertisement; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Realestate\Advertisement\Repositories\Criteria\AdvertisementResourceCriteria::class); } /** * Display a list of advertisement. * * @return Response */ public function index(AdvertisementRequest $request) { return $this->repository ->setPresenter(\Realestate\Advertisement\Repositories\Presenter\AdvertisementPresenter::class) ->paginate(); } /** * Display advertisement. * * @param Request $request * @param Model $advertisement * * @return Response */ public function show(AdvertisementRequest $request, Advertisement $advertisement) { return $advertisement->setPresenter(\Realestate\Advertisement\Repositories\Presenter\AdvertisementListPresenter::class); ; } /** * Create new advertisement. * * @param Request $request * * @return Response */ public function store(AdvertisementRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('advertisement::advertisement.name')]); $code = 204; $status = 'success'; $url = guard_url('advertisement/advertisement/' . $advertisement->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('advertisement/advertisement'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the advertisement. * * @param Request $request * @param Model $advertisement * * @return Response */ public function update(AdvertisementRequest $request, Advertisement $advertisement) { try { $data = $request->all(); $advertisement->update($data); $message = trans('messages.success.updated', ['Module' => trans('advertisement::advertisement.name')]); $code = 204; $status = 'success'; $url = guard_url('advertisement/advertisement/' . $advertisement->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('advertisement/advertisement/' . $advertisement->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the advertisement. * * @param Model $advertisement * * @return Response */ public function destroy(AdvertisementRequest $request, Advertisement $advertisement) { try { $advertisement->delete(); $message = trans('messages.success.deleted', ['Module' => trans('advertisement::advertisement.name')]); $code = 202; $status = 'success'; $url = guard_url('advertisement/advertisement/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('advertisement/advertisement/' . $advertisement->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }