Problem getting the right data from my tables to show (Laravel 7 eloquent models)

Problem getting the right data from my tables to show (Laravel 7 eloquent models)

Guyke187Guyke187 Posts: 5Questions: 3Answers: 0
edited April 2022 in Free community support

Hello, I'm not sure where to post this since I'm new to these forums, so correct me if I posted it wrong.
So as the title says I'm working on a project in Laravel 7 with eloquent models, but I'm having a hard time showing the data that's a couple of tables deeper. Everything has a hasMany or belongsTo relationship with each other so no problems there.
This is how my controller is set up:
My tables are like this: User->consultant->consultantOpportunity->timesheet->workday->dayType. Now I try to show all the workdays from the consultant that's logged in. That's what the orange-marked code is for. This works since I only get the consultant that's logged in to show. But now I need to go deeper. I specified the relationships in the yellow marked code. And as you can see I need to get from Consultant to Workdays which is 3 tables deeper. In the blue marked code, I tried to throw the code in a data tag so I maybe could just split it up with jquery/ajax but it's a little too much as you can see here:.
I commented out the data I wanna get for now since it doesn't work.
but it might give you an idea what I try to achieve. I wanna read out like start hour, end hour, etc. from the Workday table. If I start from the Workday table then I can read all the data out but then it just gives me all workdays in the table and not only from the
consultant logged in. (The consultant needs to be able to register his own worked hours per day)
Idk if there is a simple way to do this? Any help is appreciated. Sorry for my bad English, if you need any additional information let me know and I'll try to explain it better with some extra pictures. Thanks.

Answers

  • allanallan Posts: 63,237Questions: 1Answers: 10,418 Site admin

    Can you show me the JSON that the server is returning please? You'll probably need to use the array / parameter syntax for columns.data - e.g. myTable[, ].date, but it will depend upon the JSON format.

    Allan

Sign In or Register to comment.