Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]laravel - wyszukiwanie w polach z relacją typu JSON
trifek
post 26.01.2021, 15:36:41
Post #1





Grupa: Zarejestrowani
Postów: 340
Pomógł: 0
Dołączył: 28.09.2015

Ostrzeżenie: (0%)
-----


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:

  1. Product:
  2.  
  3.  
  4. class Product extends Model implements Presentable
  5. {
  6. ....
  7. public function featureProducts()
  8. {
  9. return $this->hasMany(FeatureProduct::class, 'product_id');
  10. //return $this->belongsToMany(Feature::class, 'feature_product', 'id');
  11. }
  12. }
  13.  
  14.  


FeatureProduct

  1. class FeatureProduct extends Model
  2. {
  3. protected $table = "feature_product";
  4.  
  5. protected $with = [
  6. 'values'
  7. ];
  8.  
  9. public function values()
  10. {
  11. return $this->belongsTo(FeatureValue::class, 'feature_values_ids', 'id');
  12. }
  13.  
  14. }


FeatureValues:
  1.  
  2. class FeatureValue extends Model
  3. {
  4. use SoftDeletes,
  5. Translatable;
  6.  
  7. protected $fillable = [
  8. 'feature_id',
  9. 'value'
  10. ];
  11.  
  12. protected $dates = [
  13. 'created_at',
  14. 'updated_at',
  15. 'deleted_at'
  16. ];
  17.  
  18. protected $translatable = [
  19. 'value'
  20. ];
  21.  
  22. public function feature(): BelongsTo
  23. {
  24. return $this->belongsTo(Feature::class);
  25. }
  26.  
  27. public function getAdminUrlAttribute(): AbstractAdminUrlPresenter
  28. {
  29. return new FeatureValueUrlPresenter($this);
  30. }
  31. }
  32.  



Problem jest z wyszukiwaniem w json: feature_product. feature_values_ids

Kiedy mam normalne liczby, relacja działa poprawnie:



  1. public function values()
  2. {
  3. return $this->belongsTo(FeatureValue::class, 'feature_values_ids', 'id');
  4. }


Problem jest z json:

  1. ["1", "2","3"]



Nie mam żadnych wyników sad.gif


W jaki sposób mogę to naprawić?


Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 19.03.2024 - 09:24