Hello,
I try to find how to have only result where the relation return something, not when there empty.
I try this :
$c = Produit::whereNotIn('id_dispo', array(Statut_Dispo::FERME, Statut_Dispo::VENDU))
->with( array ('categorie' => function ($query) use ($id) {
$query->where('categorie.id_categorie' , $id);
}))
->get();
Return :
{
"id_produit":"21870",
"reference":"21870",
"created_at":"2014-08-05 21:50:06",
"updated_at":"-0001-11-30 00:00:00",
"deleted_at":null,
"prix":"50",
"prixha":null,
"qte":"1",
"stock_initial":"1",
"id_dispo":"2",
"featured":"0",
"id_utilisateur_creation":"6",
"id_utilisateur_modification":null,
"id_lot":"1",
"id_taxe":"1",
"hash":null,
"km":"53242",
"categorie":[
]
},
How to do if i don't want have a result when "categorie" is empty ?
Hi.
What you need is whereHas : http://laravel.com/docs/eloquent#querying-relations
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community