I have the following code where I get a random question with it's answers:
$q = Question:with(['answers' => function ($q) {
$q->inRandomOrder();
}])->inRandomOrder()->first();
but i want like this:
$q = Question:with(['answers' => function ($q) {
if(Question->random_answer==true){
$q->inRandomOrder();
}else{
$q->orderBy('sort',' ASC');
}
}])->inRandomOrder()->first();
Home some one can solve this.
Thanks,
Best regard.
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2CSJSf1
via IFTTT
Aucun commentaire:
Enregistrer un commentaire