с отношением восстановить все записи - Laravel - PullRequest
0 голосов
/ 18 октября 2018

Я хочу получить только активные организации, но база данных возвращает все записи. Вот мой код. Как вы можете видеть ниже, запись не должна возвращаться как перечисленная организация, которую я включил ниже кода, а также мою модель и результат.Я получил из базы данных

$organisations = Organisation::with(['year_status' => function ($query) use ($year_id) {
    $query->where(['year_id' => $year_id, 'is_listed' => 1]);
}])->get();

public function year_status()
{
    return $this->hasMany('App\OrganisationYearStatus');
} 

и что получил:

11 => Organisation {#630 ▼
      #fillable: array:8 [▶]
      #connection: "mysql"
      #table: null
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:14 [▼
        "id" => 39
        "organisation" => "Test Organisation"
        "sector_id" => 1
        "country_id" => 1
         ]
      #original: array:14 [▶]
      #changes: []
      #casts: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: array:1 [▼
        "year_status" => Collection {#632 ▼
          #items: []
        }
      ]
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #guarded: array:1 [▶]
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...