Monday, April 10, 2017

Search query does not written array object

I am working in laravel5.4. I have written 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);

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.



via Nisarg Bhavsar

Advertisement