sql >> Database teknologi >  >> RDS >> Mysql

Sådan bruges Relation::morphMap() til en anden klasse

Lad os starte med at definere de polymorfe relationer

Første forhold...

Package.php

public function provider() {
  return $this->morphTo(null, 'map_type_id', 'map_id');
}

Venue.php

public function packages() {
  // you should provide the relation name, in our exemple its called `provider` as a second parameter
  return $this->morphMany(VendorPackage::class, 'provider', 'venues');
}

Vendor.php

public function packages() {
  // you should provide the relation name, in our exemple its called `provider` as a second parameter
  return $this->morphMany(VendorPackage::class, 'provider', 'vendors');
}

Anden relation

TicketBooking.php

public function provider() {
  return $this->morphTo(null, 'map_type_id', 'map_id');
}

Venue.php

public function bookings() { 
  return $this->morphMany(TicketBooking::class, 'provider', 'venues');
}

Decors.php

public function bookings() {
  return $this->morphMany(TicketBooking::class, 'provider', 'decors');
}

og registrer Relation::morphMap som

Relation::morphMap([
  'vendors' => \Vendor::class,
  'venues' =>  \Venue::class,
  'decors' =>  \Decor::class
]);



  1. Gør mens loop i SQL Server 2008

  2. rangordnede poster i mysql-tabel

  3. Deaktiver alle tabelbegrænsninger i Oracle

  4. Sådan flyttes datafiler i SQL Server - Del 1