Sunday, March 4, 2018

Laravel foreach in one item? - development

Laravel foreach in one item?

i have a relationship like

+------------+---------+
|    id      | problem |
+------------+---------+
| 1          | problem |    
+------------+---------+


+------------+----------+---------+
|    id      | problemid|solution |
+------------+----------+---------+
| 1          |  1       |solution1|    
+------------+----------+---------+
| 2          |  1       |solution2| 
+------------+----------+---------+

I have done a join and the problem is when i do a foreach in the view i get 2 items with the same problem and 2 different solutions but i need to get the same problem (one problem) and 2 solutions. How can i do it?

Here is the code in Controller:

$problem=Problem::select()
            ->join('solution','problem.id','=','solution.problemid')
            ->where('problem.id',$id)
            ->get();



from Laravel Questions and Answers https://laravelquestions.com/php/laravel-foreach-in-one-item/
via Lzo Media

No comments:

Post a Comment