laravel - Laravel 5.8 无法获取 api token 字段填写
问题描述
我正在尝试使用 Laravel 5.8 完成一个 api 注册系统。每次我运行注册时,api_token 字段都保持为空。我很确定我正确地遵循了说明,但我仍然遇到错误。
这是我创建的迁移。
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class UpdateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
Schema::table('users', function ($table) {
$table->string('api_token', 80)->after('password')
->unique()
->nullable()
->default(null);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
以下是注册控制器中的创建方法。
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'api_token' => Str::random(60),
]);
}
这几乎就像在此过程中完全忽略了“api_token”字段。所有其他字段均在此过程中完成。
解决方案
首先让我看看:您是否在用户模型的用户$ fillable 数组中添加了“api_token”?
推荐阅读
- python - Python matplotlib:从matplotlib的工具栏中删除“配置子图”工具会导致错误
- windows - 检索 Windows 10 电源模式滑块的状态
- python - 在列表中查找字符串的列表理解?
- android - 有什么问题,我从 Firebase 得到 0 作为值吗?
- spring-boot - 无法覆盖詹金斯中的服务器端口
- r - 用正态分布覆盖直方图
- azure - 我可以对 Azure 应用服务进行实时威胁防护吗
- c# - 使用 EF Core 进行 CQRS/ES 投影重播
- jenkins - 重启后的 Jenkins 错误:java.lang.IllegalStateException:预期 1 个 hudson.model.User$AllUsers 实例但得到 0
- javascript - 动态获取keycloak.json?