-2
Guys, I have an app Laravel and I am needing to insert a value that is going through a first serealize()
in PHP in my database in a field string.
This is the array
$dia_semana = array(serialize($request->dia_semana));
dd($dia_semana);
This is the result:
array:1 [▼
0 => "a:3:{i:0;s:1:"0";i:1;s:1:"1";i:2;s:1:"2";}"
]
I need it inserted into the field "weekday (string/varchar)" in the bank as follows 0, 1, 2, 3
being 0-second, 1-third, 2-fourth and so on. This field is a checkbox in my application it can mark 1 or several days.
First of all, I’m not sure I needed the array()
before serialize.
If I remove mine dd()
the code falls on my catch()
returning
Array to string Conversion
I believe that precisely because of the above problem array untreated.
Think to me, if you want to save a string, why create an array?
– Woss
opa, good morning Andy, he already creates an array by serialize brother, let’s say, transform this serialize array into "0,1,2".
– Claudio Emmanuel
How do you create the array by serialize? It’s not by
array()
that you create the array?– Woss
what I meant was that with the
array()
or he no longer becomes one "array" by serealize– Claudio Emmanuel
That doesn’t make sense. By itself documentation of the function itself
serialize
returns a string.– Woss
By the way, why are you Serializing your object? If
$request->dia_semana
is a array, then it wouldn’t be enough to dojoin(', ', $request->dia_semana)
?– Woss
opa, already got here what I wanted, I did what the friend Orge below said using
$casts
and then used the implode$dia = implode(',', $request->dia_semana);
the result was what I expected "1,2,3", thanks anyway.– Claudio Emmanuel