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