Skip to content

Instantly share code, notes, and snippets.

@iwankgb
Last active May 14, 2016 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iwankgb/dc54e1e2b20cc566ad95 to your computer and use it in GitHub Desktop.
Save iwankgb/dc54e1e2b20cc566ad95 to your computer and use it in GitHub Desktop.
<?php
/*
* Wykorzystując Illuminate\Database\Query\Builder wyciągam dane z bazy
*/
$result = \DB::table('a')->join('b', 'a.id', '=', 'b.a_id')->where('b.id', 1)->get();
/*
* Po tej operacji będę miał w garści tablicę instancji stdClass (albowiem ten akurat builder nie wie nic o modelu)
* w związku z tym hydruję model i iteruję po wyniku
*/
$models = A::hydrate($results);
foreach ($models as $model) {
/*
* Mam też na stanie tabelę c - pozostającą w relacji n:1 z a
* W związku z tym poniższy wiersz spowoduje wysłanie do bazy zapytania dla każdej z iteracji pętli
*/
$model->a();
}
@iwankgb
Copy link
Author

iwankgb commented Feb 14, 2015

Nie uruchamiałem tego kodu, mogą w nim być jakieś głupie błędy. Koncepcja jest imho dość jasna.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment