rubanraj54 / vue-bootstrap4-table

Advanced table based on Vue 2 and Bootstrap 4 ⚡️
MIT License
219 stars 57 forks source link

Parse the queryParams in php via Laravel from the array to object. #29

Closed grafxflow closed 5 years ago

grafxflow commented 5 years ago

Is there a way to parse the queryParams in php via Laravel from the array to object.

I have tried...

$querystring = json_decode(json_encode($request->all()), false);

But I get an object which contains the arrays inside.

stdClass Object
(
    [queryParams] => {"sort":[],"filters":[],"global_search":"","per_page":10,"page":1}
    [page] => 1
)
grafxflow commented 5 years ago

Issue has been sorted.

rubanraj54 commented 5 years ago

Hi @grafxflow ,

Good to see that you solved this issue.

Anyway, I will give my thoughts about this issue here so it will be helpful for others.

Long back I also faced this issue when I used this component with Laravel.

In the below code, you can see how to decode the json string to object or array style and how to access them.

<?php

// $queryParams = $request->queryParams;

$queryParams = '{"sort":[],"filters":[],"global_search":"","per_page":10,"page":1}';

// if you want to use object style
$objectMode = json_decode($queryParams);
var_dump($objectMode->sort);

// if you want to use array style
$arrayMode = json_decode($queryParams,true);
var_dump($arrayMode["sort"]);

?>

Hope this helps you, as well as others in future. I will close this issue now.

Cheers, Ruby.