I am writing a seo plugin for tailor but I have a problem when saving data. hope to receive help from you guys.
model: SeoSetting.php
<?php namespace Kenshin\SeoTailor\Models;
use Model;
class SeoSetting extends Model
{
protected $table = 'kenshin_seo_tailor';
protected $fillable = ['post_id', 'seo_title', 'seo_description', 'seo_keywords'];
public $timestamps = true;
public function tailorEntry()
{
return $this->belongsTo(\Tailor\Models\EntryRecord::class, 'post_id');
}
}
Plugin.php
public function boot()
{
Event::listen('backend.form.extendFields', function($widget) {
if (!$widget->model instanceof EntryRecord) {
return;
}
if ($widget->model->blueprint->handle === 'blogPost') {
return;
}
// Thêm tab SEO
$widget->addTabFields([
'seo[seo_title]' => [
'label' => 'SEO Title',
'type' => 'text',
'tab' => 'SEO',
],
'seo[seo_description]' => [
'label' => 'SEO Description',
'type' => 'textarea',
'tab' => 'SEO',
],
'seo[seo_keywords]' => [
'label' => 'SEO Keywords',
'type' => 'text',
'tab' => 'SEO',
],
]);
$widget->bindEvent('form.save', function() use ($widget) {
$data = post('seo', []);
print_r($data );
SeoSetting::updateOrCreate(
['post_id' => $widget->model->id],
[
'seo_title' => $data['seo_title'] ?? '',
'seo_description' => $data['seo_description'] ?? '',
'seo_keywords' => $data['seo_keywords'] ?? ''
]
);
});
});
}
The error is shown as follows when I create a post and try to click the save button
“SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘seo’ in ‘field list’ (SQL: update
xc_edcd102e05254e4db07e633ae6c18db6c
settitle
= test,slug
= test,is_enabled
= 1,draft_mode
= 3,primary_attrs
= [],published_at_month
= 08,content
=tét
,featured_text
= ,seo
= {“seo_title”:“test”,“seo_description”:“test”,“seo_keywords”:“test”},xc_edcd102e05254e4db07e633ae6c18db6c
.updated_at
= 2024-08-28 02:31:44 whereid
= 78)” on line 760 of C:\xampp\htdocs\mori\vendor\laravel\framework\src\Illuminate\Database\Connection.php
Thank you!