dingo / dingo/api

How to use jsonp for some api route by easy way?

Open
#1,389 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
9.4k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

I try

```php
'formats' => [

'json' => Dingo\Api\Http\Response\Format\Json::class,
'jsonp' => Dingo\Api\Http\Response\Format\Jsonp::class,

],
```

```php

return response()->jsonp('test', [‘foo’ => 'bar']); // blank

return $this->response->array(['foo' => 'bar'])->morph('jsonp'); // {"message":"Trying to get property of non-object","status_code":500}
```
```php
$formatter = new Jsonp();
$formatter->setRequest($request);
$response = $this->response->array(['foo' => 'bar']);
$response->addFormatter('jsonp', $formatter);
$response->morph('jsonp');

return response($response->getContent())->withHeaders([
'Content-Type' => 'application/javascript',
]);
```
Its work!

But Its to complex. there is some easy way to do this?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.