Laravel 4 DB :: table - Foreach

I'm trying to run a sql query and return all values into an array of the tables names...

This is what I have so far:

$vehiclemodeldata = DB::table('model')->where('model_id', $viewData['model_id'])->get();
$row = $vehiclemodeldata->row();
foreach ($row as $key => $value){

   $viewData['vehiclemodeldata_'.$key]= $value;

}

What are your throughts?

EDIT

I've tried this it seems to bring it back in an array but I can't access the array for some reason.

$VehicleModel = DB::table('model')->where('model_id', $viewData['model_id'])->get();

Thanks

This is because $vehiclemodeldata = DB::table('model')->where('model_id', $viewData['model_id'])->get(); actually returns an object instead of an array.

Your foreach loop is correct. You can later access properties in the array by using syntax like this $viewData['vehiclemodeldata_1']->yourProperty; which is used to access properties of objects.

Hope it answers the question.

$vehiclemodeldata = DB::table('model')->where('model_id', $viewData['model_id'])->first();
$viewData['vehiclemodeldata'] = $vehicle->toArray();


But why would you like to do this?
I would pass query result directly to view instead

$vehicle = DB::table('model')->where('model_id', $id)->first();

return View::make('whateverview', compact('vehicle'));

// view file
Model: {{ $vehicle->model }}
...