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