repository = $company; parent::__construct(); } /** * Display a list of company. * * @return json */ public function index(CompanyRequest $request) { $companies = $this->repository ->setPresenter('\\Payroll\\Company\\Repositories\\Presenter\\CompanyListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->all(); $companies['code'] = 2000; return response()->json($companies) ->setStatusCode(200, 'INDEX_SUCCESS'); } /** * Display company. * * @param Request $request * @param Model Company * * @return Json */ public function show(CompanyRequest $request, Company $company) { $company = $company->presenter(); $company['code'] = 2001; return response()->json($company) ->setStatusCode(200, 'SHOW_SUCCESS');; } /** * Show the form for creating a new company. * * @param Request $request * * @return json */ public function create(CompanyRequest $request, Company $company) { $company = $company->presenter(); $company['code'] = 2002; return response()->json($company) ->setStatusCode(200, 'CREATE_SUCCESS'); } /** * Create new company. * * @param Request $request * * @return json */ public function store(CompanyRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.api'); $company = $this->repository->create($attributes); $company = $company->presenter(); $company['code'] = 2004; return response()->json($company) ->setStatusCode(201, 'STORE_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4004, ])->setStatusCode(400, 'STORE_ERROR'); } } /** * Show company for editing. * * @param Request $request * @param Model $company * * @return json */ public function edit(CompanyRequest $request, Company $company) { $company = $company->presenter(); $company['code'] = 2003; return response()-> json($company) ->setStatusCode(200, 'EDIT_SUCCESS');; } /** * Update the company. * * @param Request $request * @param Model $company * * @return json */ public function update(CompanyRequest $request, Company $company) { try { $attributes = $request->all(); $company->update($attributes); $company = $company->presenter(); $company['code'] = 2005; return response()->json($company) ->setStatusCode(201, 'UPDATE_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4005, ])->setStatusCode(400, 'UPDATE_ERROR'); } } /** * Remove the company. * * @param Request $request * @param Model $company * * @return json */ public function destroy(CompanyRequest $request, Company $company) { try { $t = $company->delete(); return response()->json([ 'message' => trans('messages.success.delete', ['Module' => trans('company::company.name')]), 'code' => 2006 ])->setStatusCode(202, 'DESTROY_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4006, ])->setStatusCode(400, 'DESTROY_ERROR'); } } }