gpt4 book ai didi

php - Laravel 错误:函数 Illuminate\Database\Eloquent\Model::setAttribute() 的参数太少

转载 作者:行者123 更新时间:2023-12-05 00:39:55 30 4
gpt4 key购买 nike

我在尝试插入表时遇到以下错误 users_basics

Illuminate\Database\Eloquent\Model::setAttribute(), 1 passed in C:\xampp\htdocs\msadi\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\HasAttributes.php on line 592 and exactly 2 expected

这是我的 Controller 代码:

public function create()
{
$userId = '10';

$userBasics = new UserBasics;
$userBasics->user_id = $userId;
$userBasics->save();

return redirect('users');
}

这是我的模型:

class UserBasics extends Model
{
protected $table = 'users_basics';
protected $primaryKey = null;

protected $fillable = ['user_id'];

const UPDATED_AT = null;
const CREATED_AT = null;
}

这是我的 user_basics 迁移:

 public function up()
{
Schema::create('users_basics', function (Blueprint $table) {
$table->integer('user_id');
$table->bigInteger('adhaar_no')->nullable();
$table->string('mobile_no')->nullable();
$table->string('college_roll_no')->nullable();
$table->date('dob')->nullable();

$table->index('user_id');
});
}

我已尝试将 UPDATED_ATCREATED_ATPrimaryKey 添加到表中,但都没有奏效。 user_id 正在插入到 users_basics 表中,但错误继续显示。

最佳答案

你应该修改你的模型:

class UserBasics extends Model 
{
protected $table = 'users_basics';
protected $primaryKey = null;
public $incrementing = false;
public $timestamps = false;

protected $fillable = ['user_id'];
}

关于php - Laravel 错误:函数 Illuminate\Database\Eloquent\Model::setAttribute() 的参数太少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53942124/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com