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

Laravel API问题?

WBOY
Release: 2016-06-06 20:07:10
Original
978 people have browsed it

TraceCreateRequest里面是验证,

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

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

回复内容:

TraceCreateRequest里面是验证,

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

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

retrun response('Invalid parameters', 200);

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

Laravel API问题?

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template