Ich habe Modelle: Partido
und Coalicion
in einer many to many
Beziehung verwandt. Ich muss wissen, wenn zwei oder mehr Coalicion
hat die gleiche Partido
bezogen.Laravel: Überprüfen, ob Modelle die gleiche Relation haben
Ich hoffe, ich habe mich selbst erklärt.
Edit 1: Modell:
class Coalicion extends Model
{
public function partidos()
{
return $this->belongsToMany(Partido::class);
}
}
Lassen Sie uns sagen Benutzer einige Elemente von einem Auswahleingang ausgewählt und ich packte sie in einem Array und sie an den Controller senden.
...
public function example(Request $request)
{
$coaliciones = $request->coaliciones;
foreach ($coaliciones as $c) {
$coalicion = Coalicion::find($c);
# Here we have a list of Coalicion model in a loop
# Let's say the first iteration I can see the relationship
dump($c->partidos);
}
}
Dies zum Beispiel geben Sie mir folgende Antwort an den Browser:
Collection {#1 ▼
#items: array:2 [▼
0 => Partido {#271 ▶} #This is Partido with id 1
1 => Partido {#268 ▶}
]
}
Collection {#2 ▼
#items: array:3 [▼
0 => Partido {#279 ▶}
1 => Partido {#280 ▶}
2 => Partido {#283 ▶} #This is Partido with id 1
]
}
ich wissen muss, wenn das Element 0 der ersten Erhebung und der Artikel 2 der zweiten Sammlung gleich sind.
senden und Ihr Modell Code hier einfügen ... –
Erledigt ist ein Laravel/Beredte spezifische Frage –