repository = $employee; parent::__construct(); } /** * Display a list of employee. * * @return Response */ public function index(EmployeeRequest $request) { if ($request->wantsJson()) { return $this->getJson($request); } $this ->theme->prependTitle(trans('employee::employee.names').' :: '); return $this->theme->of('employee::admin.employee.index')->render(); } /** * Display a list of employee. * * @return Response */ public function getJson(EmployeeRequest $request) { $pageLimit = $request->input('pageLimit'); $employees = $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->setPresenter('\\Payroll\\Employee\\Repositories\\Presenter\\EmployeeListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate($pageLimit); $employees['recordsTotal'] = $employees['meta']['pagination']['total']; $employees['recordsFiltered'] = $employees['meta']['pagination']['total']; $employees['request'] = $request->all(); return response()->json($employees, 200); } /** * Display employee. * * @param Request $request * @param Model $employee * * @return Response */ public function show(EmployeeRequest $request, Employee $employee) { if (!$employee->exists) { return response()->view('employee::admin.employee.new', compact('employee')); } Form::populate($employee); return response()->view('employee::admin.employee.show', compact('employee')); } /** * Show the form for creating a new employee. * * @param Request $request * * @return Response */ public function create(EmployeeRequest $request) { $employee = $this->repository->newInstance([]); Form::populate($employee); return response()->view('employee::admin.employee.create', compact('employee')); } /** * Create new employee. * * @param Request $request * * @return Response */ public function store(EmployeeRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $employee = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('employee::employee.name')]), 'code' => 204, 'redirect' => trans_url('/admin/employee/employee/'.$employee->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show employee for editing. * * @param Request $request * @param Model $employee * * @return Response */ public function edit(EmployeeRequest $request, Employee $employee) { Form::populate($employee); return response()->view('employee::admin.employee.edit', compact('employee')); } /** * Update the employee. * * @param Request $request * @param Model $employee * * @return Response */ public function update(EmployeeRequest $request, Employee $employee) { try { $attributes = $request->all(); $employee->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('employee::employee.name')]), 'code' => 204, 'redirect' => trans_url('/admin/employee/employee/'.$employee->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/employee/employee/'.$employee->getRouteKey()), ], 400); } } /** * Remove the employee. * * @param Model $employee * * @return Response */ public function destroy(EmployeeRequest $request, Employee $employee) { try { $t = $employee->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('employee::employee.name')]), 'code' => 202, 'redirect' => trans_url('/admin/employee/employee/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/employee/employee/'.$employee->getRouteKey()), ], 400); } } }