Привет! Я использую столбец json при переносе и пытаюсь сохранить значения в данных через модель. Вот моя миграция,
Schema::create('notifications', function (Blueprint $table) {
$table->increments('id');
$table->json('title');
$table->json('message')->nullable();
$table->timestamps();
});
А это мой код модели,
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;
class Notification extends Model
{
use HasTranslations;
public $translatable = ['title','message'];
protected $fillable = [
'title','message'
];
},
А это мой код вставки,
$notification = new Notification();
$notification_title = [
'en' => 'Request created',
'it' => 'Richiesta creata',
];
$notification_title = json_encode($notification_title);
$notification_message = [
'en' => 'Request created',
'it' => 'Richiesta creata',
];
$notification_message = json_encode($notification_message);
$notification->title = $notification_title;
$notification->message = $notification_message;
$notification->save();
Похоже, что поля JSON не сохраняются должным образом.