【问题标题】:"The selected item is invalid" - NextJS + Laravel / 422 Error“所选项目无效” - NextJS + Laravel / 422 错误
【发布时间】:2021-07-12 07:35:38
【问题描述】:

我有这个问题... 我创建了一个新的地点记录,然后我检查它是否存在。

到目前为止一切顺利,但现在当我想将它链接到某个餐厅时,它返回 422 错误。

我一直在寻找答案,但我不明白我做错了什么。

这是我的代码:

    public function store(Request $request){

    $this->authorize('create', Feeding::class);

    $request->validate([
        'date' => 'required|date|max:255',
        'food' => 'required|string|max:255',
        'observation' => 'required|string',
        'quantityLunchs' =>'required|integer',
        'user_id' => 'required|exists:users,id',
        'artist_id' => 'required|exists:artists,id',
        'place_id' => 'required|exists:places,id',

    ], self::$messages);

    $feeding = Feeding::create($request ->all());
    return response() -> json($feeding, 201); //success
}

我在邮递员中使用的标题:

授权:不记名令牌

接受: application/json

有什么解决办法吗? 坦克你

【问题讨论】:

    标签: laravel postman http-status-code-422


    【解决方案1】:

    好的,我解决了。

    我不得不在这里替换:

    因为我想与 feed_places 相关联,而不是与地点相关联 呸! ?

    【讨论】:

    • 不要使用图像,因为它们会下降,然后这个问题就没有意义了,因为你看不到数据,因为它在图像中......复制粘贴代码......跨度>
    猜你喜欢
    • 2022-11-24
    • 2022-11-11
    • 2019-07-24
    • 1970-01-01
    • 2018-08-21
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 2020-09-05
    相关资源
    最近更新 更多