我在下面附上了三个关系表。
https://drive.google.com/file/d/1q1kdURIwFXxHb2MgdRyBkE1e3DMug7r-/view?usp=sharing
我还有三个单独的模型,其中定义了所有表之间的关系。我可以使用hasManyThrough()关系从国家/地区模型中读取城市模型的信息,但无法从城市模型中读取国家/地区信息。我尝试使用“hasManyThrough”检索城市模型,但没有得到结果(附加为注释国家方法)。请阅读我的模型及其关系方法。
有人可以帮助我使用 Eloquent 方法hasManyThrough / hasManyThrough或使用逆来 获取城市模型的信息吗hasManyThrough / hasManyThrough?
01.
<?php
namespace App\Hrm;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Country extends Model
{
//use SoftDeletes;
protected $fillable = ['name','description','status'];
public function districts(){
return $this->hasMany(District::class);
}
public function cities(){
return $this->hasManyThrough(City::class,District::class);
}
}
Run Code Online (Sandbox Code Playgroud)
02.
<?php
namespace App\Hrm;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class District extends Model
{
//use SoftDeletes;
protected $fillable = ['country_id','name','description','status'];
public function country(){
return $this->belongsTo(Country::class);
}
public function cities(){
return $this->hasMany(City::class);
} …Run Code Online (Sandbox Code Playgroud) sometimes we load something in es6 like:
import FlatList from 'react-native';
Run Code Online (Sandbox Code Playgroud)
but sometimes we covered this imported object with curly brackets like
import {'FlatList'} from 'react-native';
Run Code Online (Sandbox Code Playgroud)
please tell me when should use this brackets or not.
ecmascript-6 ×1
eloquent ×1
javascript ×1
laravel ×1
mysql ×1
php ×1
react-native ×1
vue.js ×1