admin管理员组文章数量:1122832
In Laravel 10 / nova 4.27 app ProductAttribute model belongs to Product model
class ProductAttribute extends Model
{
protected $table = 'product_attributes';
protected $primaryKey = 'id';
protected $fillable = ['product_id', 'key', 'value' ];
public function scopeGetByProductId($query, int $productId= null)
{
if (!empty($productId)) {
$query->where($this->table . '.product_id', $productId);
}
return $query;
}
public function product(){
return $this->belongsTo(Product::class, 'product_id','id');
}
and Product model :
class Product extends Model implements HasMedia
{
use Sluggable, InteractsWithMedia;
use HasHeartbeats;
protected $table = 'products';
protected $primaryKey = 'id';
public function productAttributes(): HasMany
{
return $this->hasMany(ProductAttribute::class);
}
I created a ProductAttribute Repeatable component with command :
php artisan nova:repeatable ProductAttribute
with fields :
class ProductAttribute extends Repeatable
{
public function fields(NovaRequest $request)
{
return [
Text::make(__('Key'))->rules('required', 'max:255'),
Textarea::make('Value')->rules('required', 'max:255'),
];
}
and in app/Nova/Product.php in fields mehod :
HasMany::make(name: __('Product attributes'), attribute: 'productAttributes', resource: \App\Nova\ProductAttribute::class)->fullWidth(),
and having data :
What I see in Product attributes block :
Opening editor :
and when I try to saveentered data I got error :
[2024-11-22 10:51:09] local.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'productAttributes' in 'field list' (Connection: mysql, SQL: update `product_attributes` set `productAttributes` = [{"type":"product-attribute","fields":{"key":"11","value":"11111"}}], `product_attributes`.`updated_at` = 2024-11-22 10:51:09 where `id` = 5) {"userId":1,"exception":"[object] (Illuminate\\Database\\QueryException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'productAttributes' in 'field list' (Connection: mysql, SQL: update `product_attributes` set `productAttributes` = [{\"type\":\"product-attribute\",\"fields\":{\"key\":\"11\",\"value\":\"11111\"}}], `product_attributes`.`updated_at` = 2024-11-22 10:51:09 where `id` = 5) at /mnt/_work_sdb8/wwwroot/lar/NovaProducts/vendor/laravel/framework/src/Illuminate/Database/Connection.php:829)
[stacktrace]
What is wrong in my options ?
本文标签: laravel novaWrong options in Repeatable component raised errorStack Overflow
版权声明:本文标题:laravel nova - Wrong options in Repeatable component raised error? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736305028a1932445.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论