another “can't save multiple checkbox” and “must be of the type array, string given”

another “can't save multiple checkbox” and “must be of the type array, string given”



I have seen many same question about this problem but I can't figure out how to fix mine



so I'm trying to save multiple checkbox and I think this one will work but now I get "must be of the type array, string given".



By the way this is my controller


public function store(Request $request)
{
// $multi = Multi::create($request->only(['data'])->implode(', '));
// $multi = Multi::select('data')->implode();

$multis = implode(',', $request->get('data'));
$multis = Multi::create(['data' => $request->get('data')]);

return redirect()->route('multi.create')->with('success', 'berhasil.');



and this is my create.blade.php


@foreach($multis as $multi)
$multi['data']<br>
@endforeach
<br>----------------<br>

Form::open(['action'=>'MultiController@store'])
Form::checkbox('data','A')A<br>
Form::checkbox('data','B')B<br>
Form::checkbox('data','C')C<br>
Form::submit('TAMBAH')
Form::close()





What is the Multi class? Is it a library (then provide a link) or a self-made class (then provide the code)?
– Finesse
Aug 23 at 4:54



Multi





My guess is Multi is a model.
– DigitalDrifter
Aug 23 at 5:33


Multi





ohh right, im sorry.... and yes multi ismodel
– Gigsy M
Aug 23 at 7:04




3 Answers
3



Try this


$multis = implode(',', $request->data));
$multis = Multi::create(['data' => $multis]);





hey thanks! this one work <3
– Gigsy M
Aug 23 at 7:04





i still need to learn more i guess, thanks again
– Gigsy M
Aug 23 at 7:06





uhhh sir i got new problem... sooo your code work if when i insert multiple checkbox for 1field, and im trying to insert 4 multiple field now and cant find the solution.
– Gigsy M
Aug 24 at 7:08





umm ill write the code below
– Gigsy M
Aug 24 at 7:09




sooo code from GAURAV VAGHELA is working but it only work work if i insert 1 field, and im trying to insert 4 multiple field and still cant find the solution...



im trying to save data to "d","i","s","c" instead of "data"



i have tried this


$multis= implode(',', $request->d);
$multis= implode(',', $request->i);
$multis= implode(',', $request->s);
$multis= implode(',', $request->c);
$multis= Test::create(['d','i','s','c' => $multis]);



and


$multis = implode(',', $request->d,i,s,c);
$multis = Test::create(['d','i','s','c' => $multis]);



and


$multis= implode(',', $request->['d','i','s','c']);
$multis= Test::create(['d','i','s','c' => $multis]);



none of them is work...



You have to add fields name as a key of array and define all the data into different variables like this this will work.


$multis1 = implode(',', $request->d);
$multis2 = implode(',', $request->i);
$multis3 = implode(',', $request->s);
$multis4 = implode(',', $request->c);
$multis= Test::create(array('d' => $multis1,'i' => $multis2,'s' => $multis3,'c' => $multis4));





hey thanks for the answer i got another problem but its not from the implode i think, ill try to figure it out thank you very much
– Gigsy M
Aug 24 at 8:00





Welcome........
– GAURAV VAGHELA
Aug 24 at 8:02






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)