I try to get all the “books” that one user has: but I can’t do it the way I need.
I am using the following code:
$books= User::find(1)->books();
This returns me an object Collection; but I need an object Builder, as I understand it, when I use the "select" method.
Books::select(array('id', 'name', 'type'));
I need Builderinstead Collectionbecause I use Bllim / Datatables in my project and this package just accepts an object Builder...
If I send it Collection, it will throw me the following error (500 - Internal server error):
{
"error":
{
"type":"ErrorException",
"message":"Undefined property: Illuminate\\Database\\Eloquent\\Builder::$columns",
"file":"\/var\/www\/proyect\/myproyect\/vendor\/bllim\/datatables\/src\/Bllim\/Datatables\/Datatables.php",
"line":256
}
}
Does anyone know a solution?
EDIT:
When I use getQuery () method twice, I get the following error:
{"error":{"type":"ErrorException","message":"array_values() expects parameter 1 to be array, null given","file":"\/var\/www\/proyect\/myproyect\/vendor\/bllim\/datatables\/src\/Bllim\/Datatables\/Datatables.php","line":550}}
, , "select", Datatables ...
:
Books::select(array('id', 'name', 'type'));
, , :
$user = User::find(1);
$user->books()->getQuery()->getQuery();