ID, PART_NO, DESCRIPTION ..ITP.
1 RX.300.123.IW, 3000x1220x15 Itallian Walnut
Mam też tabelę ProductStructure która wyglada tak:
ID, PART_NO , COMPONENT PART
1 , RX.300.123.CW , RX.905.122.RC
2 , RX.300.123.CW , RX.666.305.WC
Oznacza to ze produkt z ID 1 sklada sie z dwóch komponentów. w czystym SQL nie ma problemu, robie group_concat i te dwa componeny robia mi sie stringiem.
Chciałbym jednak zrobić to w Eloquent czyli wyswietlic w tabeli produkty, kolumne z komponentami ale w jednym wierszu.
Pomoże ktoś to ogarnąć? Czy moze zrobic po prostu IMPLODE w widoku i jazda? Pozdrawiam
EDIT:
Dodam tylko ze jak pobieram tylko jeden problem to relacja dump wyglada tak:
Collection {#1477 ? #items: array:1 [? 0 => Product {#1476 ? #table: "Products.tblProduct" #guarded: [] #connection: "mysql" #primaryKey: "id" #keyType: "int" +incrementing: true #with: [] #withCount: [] #perPage: 15 +exists: true +wasRecentlyCreated: false #attributes: array:15 [?] #original: array:15 [?] #changes: [] #casts: [] #dates: [] #dateFormat: null #appends: [] #dispatchesEvents: [] #observables: [] #relations: array:1 [? "productStructure" => Collection {#1480 ? #items: array:2 [? 0 => ProductStructure {#1513 ? #table: "Products.tblProductStructure" #guarded: [] #connection: "mysql" #primaryKey: "id" #keyType: "int" +incrementing: true #with: [] #withCount: [] #perPage: 15 +exists: true +wasRecentlyCreated: false #attributes: array:6 [? "id" => 261 "part_no" => "RX.300.123.IW" "component_part" => "RX.905.122.RC" "component_part_description" => "3050x1220x15 Raw/Raw MDF" "created_at" => "2019-06-06 20:46:01" "updated_at" => "2019-06-06 20:46:01" ] #original: array:6 [?] #changes: [] #casts: [] #dates: [] #dateFormat: null #appends: [] #dispatchesEvents: [] #observables: [] #relations: [] #touches: [] +timestamps: true #hidden: [] #visible: [] #fillable: [] } 1 => ProductStructure {#1514 ?} ] } ] #touches: [] +timestamps: true #hidden: [] #visible: [] #fillable: [] } ] }
Czyli relacja dziala prawidlowo, jak tylko to co jest w productStructure wyswietlic w jednej linii? Potrzebuj z tego tylko component_part
EDIT:
Dla potomnych. Okazalo sie to dość proste. W widoku w petli foreach trzeba bylo to zapisać tak:
{{ $item->productStructure->pluck('component_part')->implode(', ') }}