Level 47
In 5.3 Laravel now returns collections instead of arrays.
If you want an array you can just add ->all() right after ->get() to pull the items out of the collection.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi !
I have problem with DB:: setFetchMode() on Laravel 5.3. I want to extract the data from my database in an associative array, but this line seems to do nothing... I remember it was working on 5.2.
Do you have any information or an idea of why it doesn't work ? I have a solution without this function but it's not as good as this.
Here is my model :
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use PDO;
class Client extends Model
{
protected $fillable = [
'idClient', 'nom', 'description', 'idType',
];
public function getAll(){
DB::setFetchMode(PDO::FETCH_ASSOC);
return DB::table("clients")->join('clientType', 'clientType.idType', '=', 'clients.idType')->get();
}
public function getById($idClient){
DB::setFetchMode(PDO::FETCH_ASSOC);
return DB::table("clients")->join('clientType', 'clientType.idType', '=', 'clients.idType')->where('clients.idClient', $idClient)->get();
}
}?>
Thank you !
In 5.3 Laravel now returns collections instead of arrays.
If you want an array you can just add ->all() right after ->get() to pull the items out of the collection.
Please or to participate in this conversation.