jeudi 8 septembre 2022

How to insert/save an array data into database as one value

I used checkbox to select multiple value and I was able to store it into one variable as string and display it without a problem. Unfortunately when I'm trying to save it into my database it gives me an error "Array to string conversion". What should I do to save/insert it into the database as one value. The variable that holds the array value is products.

public function mydatabase(Request $request)
{
    $data = new mydatabase;
    $data->name=$request->name;
    $data->email=$request->email;
    $data->phone=$request->phone;
    $data->address=$request->address;
    $data->date=$request->date;
    $data->time=$request->time;
    $data->products=$request->products;

    $data->save();
    return  redirect()->back();

}



Aucun commentaire:

Enregistrer un commentaire