Level 67
Why don't you use Eloquent/models and set up some relationships?
Then it would just be Vehicle::with('reservation')->get().
https://laravel.com/docs/5.6/eloquent-relationships#many-to-many
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am trying to fetch results from a joins query using DB::select( ). The query shows output in mysql phpmyadmin but not in laravel.
$q1=DB::select("Select id from vehicle"); // returns a single column of multiple ids
for($i=0; $i<=count($q1); $i++)
{
$q2=DB::select("Select * from reservation inner join vehicle on (reservation.v_id=vehicle.id) where vehicle.id=?",[$q1[$i]->id]);
// returns null when $q[$i]->id is written and returns some data when an integer is given instead of $q1 object
}
Please help if you understood my problem.
Please or to participate in this conversation.