带有请求体的Laravel DELETE方法

4 php http http-delete laravel laravel-5

我一直在尝试向FormRequest我的删除方法添加规则和消息,但请求将返回空白,并且规则每次都失败.

是否可以在删除方法中获取请求数据?

这是我的请求类:

use App\Http\Requests\Request;

class DeleteRequest extends Request
{
    /**
     * 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()
    {
        return [
            'staff_id' => ['required', 'exists:users,uid'],
            'reason' => ['required', 'string'],
        ];
    }

    /**
     * Get custom messages for validator errors.
     *
     * @return array
     */
    public function messages()
    {
        return [
            'staff_id.required' => staticText('errors.staff_id.required'),
            'staff_id.exists' => staticText('errors.staff_id.exists'),
            'reason.required' => staticText('errors.reason.required'),
            'reason.string' => staticText('errors.reason.string'),
        ];
    }
}
Run Code Online (Sandbox Code Playgroud)

和控制器:

/**
 * Handle the 'code' delete request.
 *
 * @param integer $id            The id of the code to fetch.
 * @param DeleteRequest $request The request to handle the data.
 * @return response
 */
public function deleteCode($id, DeleteRequest $request)
{
    dd($request->all());
}
Run Code Online (Sandbox Code Playgroud)

sep*_*ehr 8

即使HTTP/1.1规范没有明确声明DELETE请求不应该有实体主体,一些实现完全忽略包含您的数据的主体,例如某些版本的Jetty和Tomcat.另一方面,一些客户也不支持发送它.

把它想象成一个GET请求.你见过表格数据吗?DELETE请求几乎相同.

您可以阅读有关该主题的很多内容.从这里开始:
DELETE Request Body的RESTful替代方案

看起来你想要改变资源的状态而不是破坏它.软删除不是删除,因此需要一个PUTPATCH两个都支持实体主体的方法.如果不是软删除,则通过一次调用进行两次操作.