如何在 Laravel 8 表单请求中使用 request 对象

问题描述 投票:0回答:0

我有表单请求对象,我需要从当前请求中获取一些参数值。所以我尝试了这个

public function rules() {
        $typeId = $this->input('notification_type_id', null);  // Returns null
        $typeId = request()->get('notification_type_id', null);  // Returns null
        
        $method = $this->method()  // This works
        ...
}

我做错了什么?如果我运行 $this->__toString() 我可以看到数据,但 $this->toArray() 返回空数组。 __toString() 返回这个:

Accept:          application/json
Accept-Encoding: gzip, deflate, br
Authorization:   bearer eyJ0eXAiOiJKV1QiLCJhbGci...
Cache-Control:   no-cache
Connection:      keep-alive
Content-Length:  6202
Content-Type:    application/json
Host:            simplaq-api.localhost
Origin:          http://simplaq-api.localhost
Postman-Token:   79f634a1-c4ee-42fe-b33f-86a27a4df083
User-Agent:      PostmanRuntime/7.32.3

{
    "push_name": "Name togo Eventu",
    "company_id": 1,
    "picture_link": null,
    "title:sk": "aaaaaaaa",
    "title:en": "aaaaaaaa",
    "description:sk": "aaaaaaaaaaa 2",
    "description:en": "aaaaaaaa 2",
    "notification_type_id": 3,
    "push_notification_action": "open_app",
    "audience": "visible_only_to_all_registered_users",
    "publish_date": "2022-04-03",
    "publish_time": "12:23",
    "campaigns": "dddddddddddddddddddddddddd",
    "status": "",
} 
request laravel-8 put
© www.soinside.com 2019 - 2024. All rights reserved.