In Vorlage I Produktspezifikationen wie folgt angezeigt werden soll:Laravel: Formatierung von Daten aus Pivot-Tabelle in Vorlage
Modell
Marke: Asus
Schnittstelle
Schnittstelle: PCI Express 3.0
...
ich habe versucht, eine weitere Schleife in diesem foreach Hinzufügen, bekam aber Fehler:
foreach ($product->specifications as $specification) {
echo $specification->name . '</br>';
echo $specification->pivot->attribute . ': ' . $specification->pivot->value . '</br>';
}
Derzeit wird diese Ausgänge:
Model
Brand: Asus
Interface
Interface: PCI Express 3.0
Chipset
Chipset Manufacturer: AMD
Chipset
GPU: Radeon RX 470
Chipset
Core Clock: 1270 MHz in OC mode
Memory
Effective Memory Clock: 6600 MHz
Memory
Memory Size: 4GB
Memory
Memory Interface: 256-Bit
Memory
Memory Type: GDDR5
Ich brauche $specification->name
nur einmal angezeigt werden und dann alle Attribute und Werte unter diesem Typ.
Dies ist die Struktur der Pivot-Tabelle:
public function up()
{
Schema::create('product_specification', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->integer('product_id')->unsigned()->index();
$table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
$table->integer('specification_id')->unsigned()->index();
$table->foreign('specification_id')->references('id')->on('specifications')->onDelete('cascade');
$table->string('attribute');
$table->string('value');
});
}
Wie kann ich das erreichen? Soll ich meine Tabellenstruktur ändern?