Hello,
I have a tag system which is multilingual. Tags are stored in a table with a JSON field. This field holds translations as key->value pairs. This is my schema:
Schema::create('tags', function (Blueprint $table) {
$table->bigIncrements('id');
$table->json('name');
$table->timestamps();
});
I want to use FirstOrCreate because I assign tags during post creation, and I don't want to have two times the same tag in database. I do it like this:
$tag = tag::firstOrCreate([
'name' =>
[
'es' => $tagItem['es'],
'en' => $tagItem['en']
],
]);
Before model was multilingual and column was not json type, it worked. The behaviour now is that tags are always created. It seems that firstOrCreate cannot locate the existing record. Next picture clarifies a bit.
https://i.imgur.com/N0zYtcT.jpg
Is this a syntax issue? A bug? BTW, I'm using https://spatie.be/docs/laravel-translatable/v6/introduction
Thanks a lot