奇了怪了,加了个验证规则,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
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 1

请求Header里增加 Accept:application/json

5年前 评论

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