httprequest - Invalid argument supplied for foreach() - request? Laravel -


i have problem request. think allready know why i'm getting error don't have idea how fix it...

it's form in blade:

{!! form::open(['action' => 'trickcontroller@tags', 'class' => 'blog-form']) !!}    @foreach($ids $id)     {!! form::hidden('id[]', $id) !!}   @endforeach    {!! form::label('tags', 'tags') !!}   {!! form::text('name', null, ['class' => 'form-control', 'placeholder' => 'example, example, example']) !!}   <br>   {!! form::submit('absenden', ['class' => 'btn btn-primary']) !!} {!! form::close() !!} 

to more specific, it's because of hidden field inside foreach loop.
if i'm doing wrong, request should give me errors, instead gives me error:

invalid argument supplied foreach()  

if correct, multiple id's passed controller , whole code works. need errors request if user incorrect.

does know can against it?

my request works fine if pass single id following:

{!! form::hidden('id', 5) !!} 

thanks taking time.

found way :) -- solved code :

i used serialize function on id array

$data = serialize($id_array); 

then passed view , used in hidden field without foreach @

{!! form::hidden('id', $data) !!} 

and @ next controller function, used unserialize function

$id = unserialize($id); 

and got them array :)

the foreach loop expecting give can iterate over. imagine $ids variable using not meeting condition , you're therefore getting error invalid argument supplied foreach().

some points consider fix issue:

check how variable $ids getting set , consider rewriting how initialise variable. add code use initialise variable question receive recommendations on how change it.

check on $ids variable before pass view using checks using methods is_array($ids) or is_object($ids) , perhaps initialising empty array if returns not iterable.

or combination of both points!

hope helps.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -