Witajcie,
Mam problem z relacją z polem JSON.
Mam 3 relacje:
-
products
-
feature products
-
feature_values
Oraz tabele:
-
products: https://ibb.co/1dgjT6m
-
feature products: https://ibb.co/K9f74Wn
-
feature_values: https://ibb.co/rc3zG5W
Migracjer:
Product:
class Product extends Model implements Presentable
{
....
public function featureProducts()
{
return $this->hasMany(FeatureProduct::class, 'product_id');
//return $this->belongsToMany(Feature::class, 'feature_product', 'id');
}
}
FeatureProduct
class FeatureProduct extends Model
{
protected $table = "feature_product";
protected $with = [
'values'
];
public function values()
{
return $this->belongsTo(FeatureValue::class, 'feature_values_ids', 'id');
}
}
FeatureValues:
class FeatureValue extends Model
{
use SoftDeletes,
Translatable;
protected $fillable = [
'feature_id',
'value'
];
protected $dates = [
'created_at',
'updated_at',
'deleted_at'
];
protected $translatable = [
'value'
];
public function feature(): BelongsTo
{
return $this->belongsTo(Feature::class);
}
public function getAdminUrlAttribute(): AbstractAdminUrlPresenter
{
return new FeatureValueUrlPresenter($this);
}
}
Problem jest z wyszukiwaniem w json: feature_product. feature_values_ids
Kiedy mam normalne liczby, relacja działa poprawnie:
public function values()
{
return $this->belongsTo(FeatureValue::class, 'feature_values_ids', 'id');
}
Problem jest z json:
["1", "2","3"]
Nie mam żadnych wyników :(
W jaki sposób mogę to naprawić?