How can I access query string parameters for requests I've manually dispatched in Laravel 4?

前端 未结 3 1097
甜味超标
甜味超标 2020-12-09 12:31

I\'m writing a simple API, and building a simple web application on top of this API.

Because I want to \"consume my own API\" directly, I first Googled and found th

3条回答
  •  猫巷女王i
    2020-12-09 13:15

    If you want to invoke an internal API and pass parameters via an array (instead of query string), you can do like this:

    $request = Request::create("/api/cars", "GET", array(
       "id" => $id,
       "fields" => array("id","color")
    ));
    $originalInput = Request::input();//backup original input
    Request::replace($request->input());
    $car = json_decode(Route::dispatch($request)->getContent());//invoke API
    Request::replace($originalInput);//restore orginal input
    

    Ref: Laravel : calling your own API

提交回复
热议问题