Look at this example: https://stackoverflow.com/questions/8177993/how-can-i-get-value-through-json-array-like-query
Once you, with trial and error, figure the correct loop to loop over the data:
- In the loop if Rugby is there, then
- put that whole row into a new temp array
- once finished the looping of first array
- send second temp array to view
- now foreach using blade the array containing your Rugby
OR
As looping original json array, write to a temp table then query the table, then send results to view.
And or
Write a custom class that does this stuff.
Sorry no cut and paste code, but really a lot of what you need is just some trial and error, tweaks to get correct. Some leg work in other words.
Not a solution, but a starting point:
public function rug()
{
$data = '[
{
"name": "Joe John",
"city": "London",
"sports": [
"Football",
"Rugby",
"Basketball"
],
"description": "Voluptatem qui eum eius aut."
}, {
"name": "Josh Round",
"city": "Madrid",
"sports": [
"Rugby",
"Cricket",
"Baseball"
],
"description": "Natus in repellat voluptate vitae."
}]';
$quy = json_decode($data, true);
echo '<pre>';
print_r($quy);
echo '</pre>';
echo "<br>";
$keys = array_keys($quy);
//dd($loads);
for ($i = 0; $i < count($quy); $i++) {
foreach ($quy[$i] as $key => $value) { //$key => $value not used here
if (in_array('Rugby', $quy[$i]['sports'])) {
echo "it is there";
// So work out a routine to get all of that $i
// and put into a another temp array
// to eventually pass to a blade view.
}
}
}
}
Output:
Array
(
[0] => Array
(
[name] => Joe John
[city] => London
[sports] => Array
(
[0] => Football
[1] => Rugby
[2] => Basketball
)
[description] => Voluptatem qui eum eius aut.
)
[1] => Array
(
[name] => Josh Round
[city] => Madrid
[sports] => Array
(
[0] => Rugby
[1] => Cricket
[2] => Baseball
)
[description] => Natus in repellat voluptate vitae.
)
)
it is thereit is there
Inserting this stuff into a table so you can query it would be easier in my opinion.