【发布时间】:2021-09-13 05:22:34
【问题描述】:
这个问题和这个question类似
我没有更改表迁移中的默认autoIncrement,但是我注意到我无法从ID 中获取特定行的模型。对于其他行,它工作正常。我清除了缓存,以为这是缓存问题,但似乎不是。
行为
我有记录1,..., 58, 59, 60
当我选择模型时
$object = Post::find(59);
// $object returns null but record exists
但是我通过应用程序添加了另一条记录以检查行为是否相同,来自60 的记录不为空,这是预期的行为。有没有人遇到过这个?如果是这样,克服这个问题的最佳方法是什么。
我在 Windows 上使用 XAMPP v8.0.8
编辑: 后模型
class Post extends Model
{
use HasFactory,Searchable,SoftDeletes;
protected $fillable = [
'hash_id','user_id','location','subjects','request_type'
];
protected $casts = [
'location' => 'array',
'subjects' => 'array'
];
public function User()
{
return $this->belongsTo('App\Models\User');
}
public function searchableAs()
{
return 'posts';
}
}
迁移文件
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('hash_id')->unique();
$table->integer('user_id');
$table->json('location');
$table->json('subjects');
$table->string('request_type');
$table->timestamps();
$table->softDeletes();
});
}
【问题讨论】:
-
你能用你的 Post 模型和数据库表结构更新你的问题吗?
-
@toyi,刚刚更新