关于 Reply 模型关联 User 模型
<?php
namespace App\Models;
class Reply extends Model
{
protected $fillable = ['content'];
public function topic()
{
return $this->belongsTo(Topic::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
}
这里关联user模型使用的是User::class,如果App\Models\User 和 App\User模型同时存在,请问这个user模型会定义到哪个。官方文档里使用的是 return $this->belongsTo('App\Models\User');所以比较明确。
推荐文章: