D
D
Dadoshik2017-07-05 10:32:41
Laravel
Dadoshik, 2017-07-05 10:32:41

How to pass an array to a template?

Laravel 5.4
Received data from the JSON cell database, using explode() transferred the string to an array:

$sql = $test->party;
$pieces = explode("|", $sql);

array:1[▼
  0 => "Wlof"
  1 => "Leso"
  2 => "Dusy"
  3 => "Vova"
  4 => "Kosty"
  5 => "Zola"
  6 => "Wlof"
]

I tried to send it like this:
return view('welcome')>with([
            'pieces'=>$pieces
        ]);

Did not work out.
How to pass an array to a template? And how to address it in a template?
I want to make a check in the template for the presence of a nickname in the array.
@if(in_array($tery->nickname, $pieces, true))
...
@else
...
@endif

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dadoshik, 2017-07-05
@Dadoshik

I decided to access the cell through the model and decode it in view.
@if(in_array($lottery->nickname, json_decode($test->party, true), true))
...
@else
...
@endif

D
Dima, 2017-07-05
@avbrugen

return view('welcome', ['pieces' => $pieces]);

S
Semyon Beloglazov, 2017-07-05
@Batlab

return view('welcome')>with([
'pieces'=>$pieces
]);
You have the operator
> instead of -> written correctly before > with

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question