小编Ahm*_*hel的帖子

如何反转 Eloquent Has One 和 Has Many Through (laravel 5.8)?

我在下面附上了三个关系表。

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)

php mysql laravel eloquent

7
推荐指数
2
解决办法
4965
查看次数

Difference between import { AppRegistry } from 'react-native'; and import AppRegistry from 'react-native';

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.

javascript ecmascript-6 vue.js react-native

3
推荐指数
1
解决办法
99
查看次数