Hello,
First sorry for such long question in the heading. Will start with small story and then right to the solution fix I found.
Facing issue of getting id of Joined table in my current laravel project, where I need a Id column value from the Main table not the one which I used to inner join for the records to pull in.
Here is my existing query of Laravel returning t he id of customer table where I was looking id of Bill’s Table:
$data = Bill::join('customers', 'customers.id', '=', 'bills.customer_id')
->where('bills.store_id', 'LIKE', '%'. $storeId . '%')
->orderBy('bills.id', 'desc')
->get(['bills.*','customers.*', ]);
So the right solution is at the last line in the above code, please carefully see the get() function array parameters; I switched them, so it finally returns the id values of bills not of customer table. (as customer table also id column which matches with bill’s table column)
$data = Bill::join('customers', 'customers.id', '=', 'bills.customer_id')
->where('bills.store_id', 'LIKE', '%'. $storeId . '%')
->orderBy('bills.id', 'desc')
->get(['customers.*', 'bills.*']);
This results be the records with bills id not customer’s id in laravel elqouent or mysql inner join.
Thanks for reading and learning.
Happy learning.
Break! I didn’t plan it. One day I just didn’t feel like opening Instagram—and then…
AI tools Let’s be real—AI sounds like either a robot apocalypse or something only tech…
Summer vacation is a great time for kids to explore, have fun, and learn new…
Goal: Understand transformers, large language models, and the architecture behind ChatGPT. Tutorial Suggestions: ✅ “Transformers…
Goal: Build apps or tools with ChatGPT or GPT-4 API. Tutorial Suggestions: ✅ OpenAI API…
Goal: Learn how to prompt better, write content, brainstorm, code, etc. Tutorial Suggestions: ✅ OpenAI's…