repository = $marketplace; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Lavalite\Marketplace\Repositories\Criteria\MarketplaceResourceCriteria::class); } /** * Display a list of marketplace. * * @return Response */ public function index(MarketplaceRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Lavalite\Marketplace\Repositories\Presenter\MarketplacePresenter::class) ->$function(); } $marketplaces = $this->repository->paginate(); return $this->response->title(trans('marketplace::marketplace.names')) ->view('marketplace::marketplace.index', true) ->data(compact('marketplaces')) ->output(); } /** * Display marketplace. * * @param Request $request * @param Model $marketplace * * @return Response */ public function show(MarketplaceRequest $request, Marketplace $marketplace) { if ($marketplace->exists) { $view = 'marketplace::marketplace.show'; } else { $view = 'marketplace::marketplace.new'; } return $this->response->title(trans('app.view') . ' ' . trans('marketplace::marketplace.name')) ->data(compact('marketplace')) ->view($view, true) ->output(); } /** * Show the form for creating a new marketplace. * * @param Request $request * * @return Response */ public function create(MarketplaceRequest $request) { $marketplace = $this->repository->newInstance([]); return $this->response->title(trans('app.new') . ' ' . trans('marketplace::marketplace.name')) ->view('marketplace::marketplace.create', true) ->data(compact('marketplace')) ->output(); } /** * Create new marketplace. * * @param Request $request * * @return Response */ public function store(MarketplaceRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $marketplace = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('marketplace::marketplace.name')])) ->code(204) ->status('success') ->url(guard_url('marketplace/marketplace/' . $marketplace->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/marketplace/marketplace')) ->redirect(); } } /** * Show marketplace for editing. * * @param Request $request * @param Model $marketplace * * @return Response */ public function edit(MarketplaceRequest $request, Marketplace $marketplace) { return $this->response->title(trans('app.edit') . ' ' . trans('marketplace::marketplace.name')) ->view('marketplace::marketplace.edit', true) ->data(compact('marketplace')) ->output(); } /** * Update the marketplace. * * @param Request $request * @param Model $marketplace * * @return Response */ public function update(MarketplaceRequest $request, Marketplace $marketplace) { try { $attributes = $request->all(); $marketplace->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('marketplace::marketplace.name')])) ->code(204) ->status('success') ->url(guard_url('marketplace/marketplace/' . $marketplace->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('marketplace/marketplace/' . $marketplace->getRouteKey())) ->redirect(); } } /** * Remove the marketplace. * * @param Model $marketplace * * @return Response */ public function destroy(MarketplaceRequest $request, Marketplace $marketplace) { try { $marketplace->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('marketplace::marketplace.name')])) ->code(202) ->status('success') ->url(guard_url('marketplace/marketplace/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('marketplace/marketplace/' . $marketplace->getRouteKey())) ->redirect(); } } /** * Remove multiple marketplace. * * @param Model $marketplace * * @return Response */ public function delete(MarketplaceRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('marketplace::marketplace.name')])) ->status("success") ->code(202) ->url(guard_url('marketplace/marketplace')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/marketplace/marketplace')) ->redirect(); } } /** * Restore deleted marketplaces. * * @param Model $marketplace * * @return Response */ public function restore(MarketplaceRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('marketplace::marketplace.name')])) ->status("success") ->code(202) ->url(guard_url('/marketplace/marketplace')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/marketplace/marketplace/')) ->redirect(); } } }