middleware(function ($request, $next) { $this->form = AssetForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('bixo.asset.modules'), 'asset', guard_url('asset')); return $next($request); }); } /** * Display a list of asset. * * @return Response */ public function index(AssetResourceRequest $request) { $request = $request->all(); $page = AssetActions::run('paginate', $request); $data = new AssetsCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('asset::asset.names')) ->view('asset::asset.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display asset. * * @param Request $request * @param Model $asset * * @return Response */ public function show(AssetResourceRequest $request, Asset $model) { $form = $this->form; $modules = $this->modules; $data = new AssetResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('asset::asset.name')) ->data(compact('data', 'form', 'modules')) ->view('asset::asset.show') ->output(); } /** * Show the form for creating a new asset. * * @param Request $request * * @return Response */ public function create(AssetResourceRequest $request, Asset $model) { $form = $this->form; $modules = $this->modules; $data = new AssetResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('asset::asset.name')) ->view('asset::asset.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new asset. * * @param Request $request * * @return Response */ public function store(AssetResourceRequest $request, Asset $model) { try { $request = $request->all(); $model = AssetAction::run('store', $model, $request); $data = new AssetResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('asset::asset.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('asset/asset/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/asset/asset')) ->redirect(); } } /** * Show asset for editing. * * @param Request $request * @param Model $asset * * @return Response */ public function edit(AssetResourceRequest $request, Asset $model) { $form = $this->form; $modules = $this->modules; $data = new AssetResource($model); // return view('asset::asset.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('asset::asset.name')) ->view('asset::asset.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the asset. * * @param Request $request * @param Model $asset * * @return Response */ public function update(AssetResourceRequest $request, Asset $model) { try { $request = $request->all(); $model = AssetAction::run('update', $model, $request); $data = new AssetResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('asset::asset.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('asset/asset/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('asset/asset/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the asset. * * @param Model $asset * * @return Response */ public function destroy(AssetResourceRequest $request, Asset $model) { try { $request = $request->all(); $model = AssetAction::run('destroy', $model, $request); $data = new AssetResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('asset::asset.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('asset/asset/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('asset/asset/' . $model->getRouteKey())) ->redirect(); } } }