@aamir616pk Have you looked at the documentation for Eloquent relationships?
You can load the tasks relationship on your Project model when querying:
$projects = Project::with('tasks')->get();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello Everyone,
Let me explain the scenario, I've two SQL tables, 1st is Projects Table and 2nd is Tasks table. Projects table contains 3 projects e.g ['Project1' , 'Project2' , 'Project3'] and every project has different Number of tasks in Tasks Table by using Project_id. E.g Project1 have 3 tasks Project2 have 5 tasks Project3 have 7 tasks.
Now I want to get fetch all Projects record in array along with their tasks list,
Like
`` Array [ 0:Project1 [ 0:Task1[....] 1:Task2[...] ] 1:Project2[ 0:Task1[....] 1:Task2[...] 2:Task3[...] ] 2:Project3[ 0:Task1[....] 1:Task2[...] 2:Task3[...] 3:Task4[...] ] ] ?lease help in this case, I'm very thankful .
Best Regards
@aamir616pk Have you looked at the documentation for Eloquent relationships?
You can load the tasks relationship on your Project model when querying:
$projects = Project::with('tasks')->get();
Please or to participate in this conversation.