Region.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Region extends Model
{
protected $fillable = ['region'];
public function passport()
{
return $this->hasMany('App\passport');
}
}
passport.php
<?php
namespace 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');
}
}
答案 0 :(得分:0)
您的模型应该是这样
public function passports()
{
return $this->hasMany('App\passport','regions_id','id');
}
执行此命令
composer dump-autoload
然后执行您的工匠命令
$region = \App\Region::find(1);
$region->passports;