Closed
Description
I faced a problem that after php artisan optimize
responses are breaking.
Details:
config/app
'providers' => array(
...
'Dingo\Api\ApiServiceProvider',
)
'aliases' => array(
...
'API' => 'Dingo\Api\Facades\API',
)
base class
use Dingo\Api\Routing\Controller;
abstract class ResourceControllerAbstract extends Controller {
public function index()
{
$args = $this->checkArgs(func_get_args(), $this->resources->count() - 1);
$data = $this->getResource($args)->paginate($this->listsPerPage);
return $data;
}
}
Now, if I run composer dump-autoload
— everything works like a charm.
But if I run php artisan optimize
...
use Dingo\Api\Routing\Controller;
abstract class ResourceControllerAbstract extends Controller {
public function index()
{
$args = $this->checkArgs(func_get_args(), $this->resources->count() - 1);
$data = $this->getResource($args)->paginate($this->listsPerPage);
dd($data); // object(Illuminate\Pagination\Paginator)
return $data;
}
}
abstract class ApiControllerAbstract extends ResourceControllerAbstract {
public function index()
{
try {
$response = call_user_func_array(array('parent', 'index'), func_get_args());
dd($response); // and here comes the magic! see below
if ($response instanceof \Illuminate\Pagination\Paginator) {
return ApiResponseFormatter::format($response);
} else {
return $response;
}
} catch (\Exception $e) {
throw new NotFoundHttpException;
}
}
}
dd result
object(Illuminate\Http\Response)[306]
public 'original' => string '{"total":2,"per_page":10,"current_page":1,"last_page":1,"from":1,"to":2,"data":[{"id":"535fb8d06e6c631f936cb2a3","name":"foo"},{"id":"535fb8d06e6c631f936cb2a4","name":"bar"}]}' (length=175)
...
protected 'content' => string '{"total":2,"per_page":10,"current_page":1,"last_page":1,"from":1,"to":2,"data":[{"id":"535fb8d06e6c631f936cb2a3","name":"foo"},{"id":"535fb8d06e6c631f936cb2a4","name":"bar"}]}' (length=175)
protected 'version' => string '1.0' (length=3)
protected 'statusCode' => int 200
protected 'statusText' => string 'OK' (length=2)
protected 'charset' => null
It is a response with a string!
But if i again run composer dump-autoload
— I get here an instanse of object(Illuminate\Pagination\Paginator)
as it supposed to be and everything works ok.
Metadata
Metadata
Assignees
Labels
No labels