repository = $favorite; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Classifieds\Advertising\Repositories\Criteria\FavoriteResourceCriteria::class); } /** * Display a list of favorite. * * @return Response */ public function index(FavoriteRequest $request) { return $this->repository ->setPresenter(\Classifieds\Advertising\Repositories\Presenter\FavoritePresenter::class) ->paginate(); } /** * Display favorite. * * @param Request $request * @param Model $favorite * * @return Response */ public function show(FavoriteRequest $request, Favorite $favorite) { return $favorite->setPresenter(\Classifieds\Advertising\Repositories\Presenter\FavoriteListPresenter::class); ; } /** * Create new favorite. * * @param Request $request * * @return Response */ public function store(FavoriteRequest $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('advertising::favorite.name')]); $code = 204; $status = 'success'; $url = guard_url('advertising/favorite/' . $favorite->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('advertising/favorite'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the favorite. * * @param Request $request * @param Model $favorite * * @return Response */ public function update(FavoriteRequest $request, Favorite $favorite) { try { $data = $request->all(); $favorite->update($data); $message = trans('messages.success.updated', ['Module' => trans('advertising::favorite.name')]); $code = 204; $status = 'success'; $url = guard_url('advertising/favorite/' . $favorite->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('advertising/favorite/' . $favorite->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the favorite. * * @param Model $favorite * * @return Response */ public function destroy(FavoriteRequest $request, Favorite $favorite) { try { $favorite->delete(); $message = trans('messages.success.deleted', ['Module' => trans('advertising::favorite.name')]); $code = 202; $status = 'success'; $url = guard_url('advertising/favorite/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('advertising/favorite/' . $favorite->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); } }