私は多くの個別モデルを持っており、それらをすべて組み合わせてeagerloadingを利用したいと考えています。LaravelとEagerの負荷関係で複数の個別の雄弁なモデルを組み合わせる方法
$match_query = "select * from feeds " .
"WHERE (user_id IN ($users_size)) " .
"OR (target_id IN ($slugs_size) AND feedable_type = 'review') " .
"ORDER BY created_at DESC LIMIT 5;";
//Query works fine and return 2 results
$results = DB::select($match_query, $consolidatedArray);
//to convert returned php standard obj to array
$results = json_decode(json_encode($results), True);
$all = [];
foreach($results as $result){
$x = new \App\Feed($result);
//I am able to get relation like this for single item
// $x->user;
$all[] = $x;
}
//but this thing is not working (i am trying to eager load)
$data = $all->with('user');
私は解決策は何
ErrorException in FeedsRepository.php line 67:
Trying to get property of non-object
次のエラーを取得しますか?
は、なぜあなたはDBクラスを使用していますか? 'SomeEloquentModel :: with( 'user') - > get();' – Steve
のような必要な雄弁なクラスを使用しないと、私のクエリが複雑すぎます。補題はコードにも追加してください... – Eirtaza
これは複雑ではありません...配列の中の要素ではなく配列の 'with()'メソッドを呼び出すので、とにかく動作しませんそれ。 – phaberest