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