奇了怪了,加了个验证规则,API 请求一直返回时欢迎页?
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ProjectRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$methodValidates = $this->methodValidate();
if(!isset($methodValidates[$this->method()])){
throw new Exception("请求方法不支持");
}
return $methodValidates[$this->method()];
}
public function methodValidate()
{
return [
'POST'=>[
'title' => 'required',
'desc' => 'required',
'start_time' => 'required',
'end_time' => 'required',
],
'PUT'=>[],
'PATCH'=>[],
'DELETE'=>[],
'GET'=>[],
];
}
}
方法
public function store(ProjectRequest $request)
{
\Log::info($request->all());
$project = Project::create($request->all());
return $this->setStatusCode(201)->response($project);
}
postman
很是奇怪
推荐文章: