php artisan tinker (null) hasmany

地区.php


<?php


namespace App;


use Illuminate\Database\Eloquent\Model;


class Region extends Model

{

    protected $fillable = ['region'];


    public function passport()

    {

      return $this->hasMany('App\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');

    }

}


慕码人8056858
浏览 112回答 1
1回答

慕斯709654

你的模型应该是这样的public function passports(){&nbsp; return $this->hasMany('App\passport','regions_id','id');}执行这个命令composer dump-autoload然后执行你的工匠命令$region = \App\Region::find(1);$region->passports;
打开App,查看更多内容
随时随地看视频慕课网APP