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