/** * Store a newly created resource in storage. * * @return JsonResponse */ public function store() { try { $task = $this->task->create($this->request->all()); } catch (PDOException $e) { return $this->response->internalError(); } return $this->response->ok($task); }
/** * Make paginator * * @param Collection $collection * @return array */ public function make(Collection $collection) { $page = $this->request->get('page') ?: 1; return (new LengthAwarePaginator($this->getPageItems($collection, $page), $collection->count(), 15, $page))->toArray(); }
/** * Respond with appropriate response * * @param string $code * @param string $content * @param array $headers * @return JsonResponse|BaseResponse */ private function respond($code, $content = '', $headers = []) { return $this->request->ajax() ? new JsonResponse($content, $code, $headers) : new BaseResponse($content, $code, $headers); }
/** * Build container * * @return void */ protected function buildInitialContainer() { $builder = new ContainerBuilder(); $builder->addDefinitions([Request::class => Request::createFromGlobals(), View::class => function () { $loader = new Twig_Loader_Filesystem(__DIR__ . '/../resources/views'); $environment = new Twig_Environment($loader); return new View($environment); }]); $this->container = $builder->build(); }