奇了怪了,加了个验证规则,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
file
很是奇怪

Make everything simple instead of making difficulties as simple as possible
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 1

请求Header里增加 Accept:application/json

6年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!