我想将字符串化的JSON发送到API请求的字段之一,如下所示:
编码方式:
https://api.some.com/foo/bar?a=788&b=My+Name&c=[%7B%27name%27:%27pejman%27%7D,%7B%27Some%27:%27thing%27%7D]
解码后:
https://api.some.com/foo/bar?a=788&b=My Name&c=[{'name':'pejman'},{'Some':'thing'}]
I want to get c
parameter using $request->c
but I want to get it as a decoded JSON automatically in my controller.
这是我的PHP代码
MyRequest.php:
<?php
use InfyOm\Generator\Request\APIRequest;
class MyRequest extends APIRequest {
public function authorize() {
return true;
}
public function rules() {
return [
'a' => 'required',
'b' => 'required',
'c' => 'requried',
];
}
}
SomeController.php:
<?php
class SomeController extends Controller {
public function store(MyRequest $request) {
$c = $request->c;
$c = $request->json('c');
$c = $request->json()->all();
}
}
? I want
$c
to be a JSON decoded automatically in my controller, How can I do that? Is that event possible to do this usingMyReqest
and how?