Try this:
$Competition->attendees = serialize($teams); // The array of participants
Edit, or check out this:
https://laravel.com/docs/5.4/eloquent-mutators#attribute-casting
protected $casts = [
'attendees' => 'array',
];
So I'm working on a little project, where I wanna post like say a new competition, where u need to enter the participants when u create it, rather than having another table and then select each one.
So I wanna pass an array through with each participant in it.
but when I do, I get the classic error "QueryException: Array to string conversion"
Here is the basic code for when uploading/posting it to the sql
public function store(Request $request)
{
$teams = array(
'teamname1' => request('teamname1'),
'teamcode1' => request('teamcode1'),
'teamname2' => request('teamname2'),
'teamcode2' => request('teamcode2'),
'teamname3' => request('teamname3'),
'teamcode3' => request('teamcode3')
);
$Competition = new Competitions;
$Competition->name = request('name'); // Just a Name
$Competition->body = request('body'); // Normal Description body
$Competition->genres = request('genres'); // This return an array of selections from the categories table
$Competition->attendees = $teams; // The array of participants
$Competition->start = request('start'); // Timestamp for when it starts
$Competition->end = request('end'); // Timestamp for when it ends
$Competition->save();
return redirect('/admin/competitions');
}
I tried some different things but it always ends back to this error so I hope I can get a little help to fix it Thx in advance. =)
Try this:
$Competition->attendees = serialize($teams); // The array of participants
Edit, or check out this:
https://laravel.com/docs/5.4/eloquent-mutators#attribute-casting
protected $casts = [
'attendees' => 'array',
];
Please or to participate in this conversation.