json() public static method

Get the JSON payload for the request.
public static json ( string $key = null, mixed $default = null ) : mixed
$key string
$default mixed
return mixed
Example #1
0
 /**
  * Get the inputs directly or from the batch request input
  * @return mixed
  */
 protected function getInputs()
 {
     if (!is_null(self::$currentRequest)) {
         return self::$currentRequest->json()->all();
     } else {
         return \Input::all();
     }
 }
Example #2
0
 /**
  * Creates a Laravel route, returning a closure which passes the raw input to AngularPHP and returns the response
  */
 protected function init()
 {
     $route = func_get_arg(0);
     $this->setErrorHandler(function (\Exception $e, Request $r) {
         \Log::error($e, $r->toArray());
     });
     $endpoint = $this;
     \Route::any($route, function () use($endpoint) {
         $path = '/' . \Request::path();
         $referrer = \Request::header('referer');
         $host = \Request::header('host');
         if (($origin = \Request::header('Origin')) && count($this->corsHosts)) {
             $this->setCorsOrigin($origin);
         }
         /**
          * If being called remotely, add the domain name to the URI
          */
         if (strlen($referrer) && parse_url($referrer, PHP_URL_HOST) != $host) {
             $uri = '//' . $host . $path;
         } else {
             $uri = $path;
         }
         $request = new Request(\Request::json()->all());
         $response = $endpoint->setUri($uri)->execute($request, \Request::getMethod());
         return \Response::make($response->content, $response->code, $response->headers)->header('Content-Type', $response->contentType);
     });
 }
 public function postProduct()
 {
     $product = Request::json('product');
     $dbProduct = Product::find($product['id']);
     if ($dbProduct) {
         $dbProduct->set($product);
         $dbProduct->save();
     }
     return Response::json($dbProduct);
 }
Example #4
0
<?php

if ('dbuniquecheck' == Request::get(1)) {
    $dbdate = Request::json();
    $m = new Model($dbdate[1]);
    $query_arr = array($dbdate[2] => $dbdate[4]);
    if (trim($dbdate[3]) != '') {
        $query_arr['id@<>'] = trim($dbdate[3]);
    }
    if ($m->has($query_arr)) {
        Response::write('no');
    } else {
        Response::write('ok');
    }
} elseif ('getselvt' == Request::get(1)) {
    $tn = String::decryption(Request::post('tn'));
    $aw = String::decryption(Request::post('aw'));
    $m = new Model($tn);
    $array = $m->field('id,name')->where("pid='" . Request::post('pid') . "'" . $aw)->list_all_array();
    Response::json($array);
}
Example #5
0
});
Route::get('/students/seed', function () {
    $faker = Faker\Factory::create();
    DB::table('students')->truncate();
    for ($i = 1; $i < 25; $i++) {
        $student = new \App\Student();
        $student->name = $faker->name;
        $student->address = $faker->address;
        $student->save();
    }
});
Route::get('/students', function () {
    return \App\Student::all();
});
Route::post('/device', function () {
    $all = Request::json()->all();
    var_dump($all);
});
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| This route group applies the "web" middleware group to every route
| it contains. The "web" middleware group is defined in your HTTP
| kernel and includes session state, CSRF protection, and more.
|
*/
Route::group(['middleware' => ['web']], function () {
    //
});
Example #6
0
 /**
  * @test
  * @expectedException \Exception
  */
 public function jsonMustThrowOnEmptyString()
 {
     Request::json();
 }
    $address = $request->get('address');
    $brands = $request->get('brands');
    $categories = $request->get('categories');
    DB::beginTransaction();
    try {
        $vendor = App\Vendor::create(['name' => $name, 'address' => $address]);
        $vendor->brands()->attach($brands);
        $vendor->categories()->attach($categories);
        DB::commit();
    } catch (Exception $e) {
        DB::rollback();
    }
});
Route::put('api/vendor/{id}', function ($id) {
    $vendor = App\Vendor::find($id);
    $request = Request::json();
    $name = $request->get('name');
    $address = $request->get('address');
    $brands = $request->get('brands');
    $categories = $request->get('categories');
    DB::beginTransaction();
    try {
        $vendor->name = $name;
        $vendor->address = $address;
        $vendor->save();
        $vendor->brands()->sync($brands);
        $vendor->categories()->sync($categories);
        DB::commit();
    } catch (Exception $e) {
        DB::rollback();
    }
Example #8
0
        return View::make('error/403')->with('warning', 'You have no permission to view invoices');
    }
});
Route::filter('check-access', function () {
    // Check if the user is logged in
    if (!Sentry::getUser()->hasAccess('sysadmin')) {
        return Redirect::action('InvoiceController@index');
    }
});
/*
|--------------------------------------------------------------------------
| CSRF Protection Filter
|--------------------------------------------------------------------------
|
| The CSRF filter is responsible for protecting your application against
| cross-site request forgery attacks. If this special token in a user
| session does not match the one given in this request, we'll bail.
|
*/
Route::filter('csrf', function () {
    if (!Request::is('android/*')) {
        if (Session::token() != Input::get('_token')) {
            throw new Illuminate\Session\TokenMismatchException();
        }
    }
});
Route::filter('android', function () {
    if (!Request::json()) {
        App::abort(404);
    }
});