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