首页 > 解决方案 > 无法将数据存储到 laravel 用户模型中

问题描述

我正在尝试通过 API 请求为用户模型创建一个 crud,我已经使用 sanctum 和 UI 脚手架进行了身份验证

这是我的 api.php 文件中的路线

Route::post('/customer', function() {

    request()->validate([
        'name' => 'required',
        'email' => 'required',
        'password' => 'required',
    ]);

    return User::create([
        'name' => request('name'),
        'email' => request('email'),
        'password' => request('password'),
    ]);

});

但是当我通过请求时

POST http://localhost:8000/api/customer HTTP/1.1
Content-Type: application/json

{
    "name" : "xxx",
    "email": "xx@gmail.com",
    "password": "wqaxszcde"
}

它返回 419 未知状态

标签: phplaravelapi

解决方案


推荐阅读