Home >Backend Development >PHP Tutorial >Laravel API问题?

Laravel API问题?

WBOY
WBOYOriginal
2016-06-06 20:07:10958browse

TraceCreateRequest里面是验证,

<code>public function rules()
{
    return [
        'corpId'     => 'required|integer',
    ];
}</code>
<code>public function getA(TraceCreateRequest $request){    
  return response('ok', 200);
}</code>

如果验证不通过,那客户收到的是什么..客房比如没有传corpId过来,我这里是做api的

回复内容:

TraceCreateRequest里面是验证,

<code>public function rules()
{
    return [
        'corpId'     => 'required|integer',
    ];
}</code>
<code>public function getA(TraceCreateRequest $request){    
  return response('ok', 200);
}</code>

如果验证不通过,那客户收到的是什么..客房比如没有传corpId过来,我这里是做api的

retrun response('Invalid parameters', 200);

request里面直接限制的话会出现非json的错误页面回复,这种情况下可以直接复写request里面的response方法,这样验证出错也能返回正常的json串,而不是http错误页面和状态码。

Laravel API问题?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn