I am working in Laravel 5.4. I have written a search query and it works fine. But it does not return array object.
It return like below data:
"user" : {
2: {
"id":2,
"firstname":"xyz"
},
3: {
"id":31,
"firstname":"abc"
},
5: {
"id":42,
"firstname":"pqr"
}
}
But I need array like below:
"user" : [
{
"id":2,
"firstname":"xyz"
},
{
"id":31,
"firstname":"abc"
},
{
"id":42,
"firstname":"pqr"
}
}
I have written query like :
User::search($request->data)->paginate(5);
In model I have write code as :
public function toSearchableArray()
{
return array_only($this->toArray(), ['id', 'firstname', 'lastname']);
}
So what code should I have to change to return as per the required data?
Note: I have tried toArray() but it does not work.