middleware(function ($request, $next) { $this->form = TaskForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('bixo.schedule.modules'), 'schedule', guard_url('schedule')); return $next($request); }); } /** * Display a list of task. * * @return Response */ public function index(TaskResourceRequest $request) { $request = $request->all(); $page = TaskActions::run('paginate', $request); $data = new TasksCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('schedule::task.names')) ->view('schedule::task.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display task. * * @param Request $request * @param Model $task * * @return Response */ public function show(TaskResourceRequest $request, Task $model) { $form = $this->form; $modules = $this->modules; $data = new TaskResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('schedule::task.name')) ->data(compact('data', 'form', 'modules')) ->view('schedule::task.show') ->output(); } /** * Show the form for creating a new task. * * @param Request $request * * @return Response */ public function create(TaskResourceRequest $request, Task $model) { $form = $this->form; $modules = $this->modules; $data = new TaskResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('schedule::task.name')) ->view('schedule::task.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new task. * * @param Request $request * * @return Response */ public function store(TaskResourceRequest $request, Task $model) { try { $request = $request->all(); $model = TaskAction::run('store', $model, $request); $data = new TaskResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('schedule::task.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('schedule/task/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/schedule/task')) ->redirect(); } } /** * Show task for editing. * * @param Request $request * @param Model $task * * @return Response */ public function edit(TaskResourceRequest $request, Task $model) { $form = $this->form; $modules = $this->modules; $data = new TaskResource($model); // return view('schedule::task.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('schedule::task.name')) ->view('schedule::task.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the task. * * @param Request $request * @param Model $task * * @return Response */ public function update(TaskResourceRequest $request, Task $model) { try { $request = $request->all(); $model = TaskAction::run('update', $model, $request); $data = new TaskResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('schedule::task.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('schedule/task/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('schedule/task/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the task. * * @param Model $task * * @return Response */ public function destroy(TaskResourceRequest $request, Task $model) { try { $request = $request->all(); $model = TaskAction::run('destroy', $model, $request); $data = new TaskResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('schedule::task.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('schedule/task/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('schedule/task/' . $model->getRouteKey())) ->redirect(); } } }