After form submission, data insertion is blocked due to an array issue related to marked checkboxes
Could you help me with how to insert the options of the checkboxes already marked into the memberships table from the Filament form? However, I'm encountering an 'Array to string conversion' error
View the attachments.
Solution:Jump to solution
what is your column's name?
you have added videos in the cast but using video_id in schema
it should be video_id in casts too. (assuming the column name is video_id & column type text or json)...
4 Replies
have you added an array cast for video_id in the model?
https://filamentphp.com/docs/3.x/forms/fields/checkbox-list
https://laravel.com/docs/eloquent-mutators#array-and-json-casting
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
Yes I added this cast
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Membership extends Model
{
use HasFactory;
protected $casts = [
'videos' => 'array',
];
protected $fillable = ['user_id', 'video_id', 'abonnement_id', 'status'];
public function users(): BelongsTo
{
return $this->BelongsTo(User::class);
} public function abonnements(): BelongsTo { return $this->BelongsTo(Abonnement::class);
} } And still 'Array to string conversion' error
} public function abonnements(): BelongsTo { return $this->BelongsTo(Abonnement::class);
} } And still 'Array to string conversion' error
Solution
what is your column's name?
you have added videos in the cast but using video_id in schema
it should be video_id in casts too. (assuming the column name is video_id & column type text or json)
Fixed! You are right! Before, my column's name was 'integer'. Then I changed it to 'json' and it worked for insertion! Also, I'm using 'video_id' in the cast. Thanks for your help!