/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     try {
         $inputs = array('des_name', 'des_coors', 'des_instruction', 'related_photos');
         $obj = array('message' => 'succeeded');
         foreach ($inputs as $field) {
             $obj[$field] = $request->input($field, '');
         }
         // TODO: cuối cùng vẫn phải chạy Raw SQL -_-
         $destination = DB::table('Destination')->insertGetId(array('des_name' => $obj['des_name'], 'des_instruction' => $obj['des_instruction'], 'coordinate' => DB::raw("GeomFromText(\"POINT(" . $obj['des_coors']['latitude'] . " " . $obj['des_coors']['longitude'] . ")\")")));
         // upload selected images too
         $images_uploaded = array();
         $relPhotos = $obj['related_photos'];
         if ($relPhotos) {
             foreach ($relPhotos as $photo) {
                 if ($photo['selected']) {
                     $rq = Request::create("/admin/destination/{$destination}/photo", "POST", [], [], [], [], array('photo_url' => $photo['url'], 'photo_like' => rand(0, 100)));
                     array_push($images_uploaded, Route::dispatch($rq)->getContent());
                 }
             }
         }
         return response()->json(array('addedObject' => Destination::find($destination), 'addedPhotos' => $images_uploaded));
     } catch (\Exception $e) {
         return response()->json($e);
     }
 }
示例#2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $request = Request::create('/api/blocknotify', 'GET', ['key' => Mint\Settings::getVal('api_key'), 'blockhash' => $this->argument('blockhash')]);
     Request::replace($request->input());
     $response = Route::dispatch($request)->getContent();
     if ($this->option('debug')) {
         $this->info($response);
     }
 }
示例#3
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Exception               $e
  *
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if ($this->isHttpException($e)) {
         $code = $e->getStatusCode();
         if ($code !== 500 || App::environment('production') || App::environment('staging')) {
             $page = Page::findByInternalName($code);
             if ($page) {
                 $request = Request::create($page->url()->getLocation(), 'GET');
                 return response(Route::dispatch($request)->getContent(), $code);
             }
         }
     }
     return parent::render($request, $e);
 }
示例#4
0
 /**
  * Dispatch this request.
  *
  * @param string $method
  * 
  * @return mixed
  */
 public function dispatch($method)
 {
     // Save original input.
     $original_input = Request::input();
     // Create request.
     $request = Request::create($this->uri, $method, $this->params);
     // Replace input (maintain api auth parameters).
     Request::replace(array_merge($request->input(), array('client_id' => Request::input('client_id'), 'client_secret' => Request::input('client_secret'), 'access_token' => Request::input('access_token'))));
     // Dispatch request.
     $response = Route::dispatch($request);
     // Restore original input.
     Request::replace($original_input);
     $content = $response->getContent();
     return empty($content) ? null : json_decode($response->getContent(), true);
 }
示例#5
0
 /**
  * @param Request $request
  * @return \Illuminate\Http\Response
  */
 public function postLogin(Request $request)
 {
     $apiRequest = Request::create(route('api.v1.0.login'), 'POST', $request->only(['email', 'password']));
     $response = Route::dispatch($apiRequest);
     if ($response->status() === 200) {
         $content = json_decode($response->content());
         return redirect(route('dashboard'))->withCookie(cookie('token', $content->token, 0, null, null, false, true));
     } else {
         if ($response->status() === 401) {
             $content = json_decode($response->content());
             return redirect(route('login'))->withErrors((array) $content->errors)->withInput();
         } else {
             return redirect(route('login'))->withErrors(['generic' => ['There was a problem with the system, please try again']])->withInput();
         }
     }
 }
示例#6
0
文件: Api.php 项目: vespakoen/epi
 protected function fastRequest($uri, $method, $input = array())
 {
     $uri = $this->config['prefix'] . $uri;
     $method = strtoupper($method);
     if ($this->config['local']) {
         $oldInput = Input::all();
         Input::replace($input);
         $request = Request::create($uri, $method, array());
         $response = Route::dispatch($request);
         $content = $response->getContent();
         $code = $response->getStatusCode();
         $results = json_decode($content);
         Input::replace($oldInput);
     } else {
         if ($method === 'GET') {
             $uri .= '?' . urldecode(http_build_query($input));
         }
         $client = new Client($this->config['domain']);
         $request = $client->createRequest($method, $uri, array(), $method === 'GET' ? array() : $input)->addHeader('Content-Type', 'application/json');
         try {
             $response = $request->send();
         } catch (ClientErrorResponseException $e) {
             $response = $e->getResponse();
         }
         $code = $response->getStatusCode();
         $results = $response->json();
     }
     if (!Str::startsWith((string) $code, "2")) {
         throw new ApiException($results, $code);
     }
     return $results;
 }