form = MasterForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('pqc.coin.modules'), 'coin', guard_url('coin')); } /** * Display a list of master. * * @return Response */ public function index(MasterRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $page = Master::pushScope(new RequestScope()) ->pushScope(new MasterResourceScope()) ->simplePaginate($pageLimit); $data = new MastersCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('coin::master.names')) ->view('coin::master.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display master. * * @param Request $request * @param Model $master * * @return Response */ public function show(MasterRequest $request, Master $model) { $form = $this->form; $modules = $this->modules; $data = new MasterResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('coin::master.name')) ->data(compact('data', 'form', 'modules')) ->view('coin::master.show') ->output(); } /** * Show the form for creating a new master. * * @param Request $request * * @return Response */ public function create(MasterRequest $request, Master $model) { $form = $this->form; $modules = $this->modules; $data = new MasterResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('coin::master.name')) ->view('coin::master.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new master. * * @param Request $request * * @return Response */ public function store(MasterRequest $request, Master $model) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $model = $model->create($attributes); $data = new MasterResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('coin::master.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('coin/master/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/coin/master')) ->redirect(); } } /** * Show master for editing. * * @param Request $request * @param Model $master * * @return Response */ public function edit(MasterRequest $request, Master $model) { $form = $this->form; $modules = $this->modules; $data = new MasterResource($model); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('coin::master.name')) ->view('coin::master.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the master. * * @param Request $request * @param Model $master * * @return Response */ public function update(MasterRequest $request, Master $model) { try { $attributes = $request->all(); $model = $model->update($attributes); $data = new MasterResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('coin::master.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('coin/master/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('coin/master/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the master. * * @param Model $master * * @return Response */ public function destroy(MasterRequest $request, Master $model) { try { $model->delete(); $data = new MasterResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('coin::master.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('coin/master/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('coin/master/' . $model->getRouteKey())) ->redirect(); } } }