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