地区.php<?phpnamespace App;use Illuminate\Database\Eloquent\Model;class Region extends Model{ protected $fillable = ['region']; public function passport() { return $this->hasMany('App\passport'); }}护照.php<?phpnamespace App;use Illuminate\Database\Eloquent\Model;class passport extends Model{ protected $table = 'passport'; protected $fillable = ['name', 'no_pass', 'negara', 'city', 'image', 'regions_id']; public function region() { return $this->belongsTo('App\region'); }}
1 回答
慕斯709654
TA贡献1840条经验 获得超5个赞
你的模型应该是这样的
public function passports()
{
return $this->hasMany('App\passport','regions_id','id');
}
执行这个命令
composer dump-autoload
然后执行你的工匠命令
$region = \App\Region::find(1);
$region->passports;
- 1 回答
- 0 关注
- 111 浏览
添加回答
举报
0/150
提交
取消