public function events()
{
return $this->belongsToMany(MusicEvent::class,'music_event_artist','artist_id','music_event_id')
->withPivot("id","artist_id","music_event_id")
->using(EventArtist::class);
}public function artists()
{
return $this->belongsToMany(Artist::class,'music_event_artist','music_event_id','artist_id')
->withPivot("id","artist_id","music_event_id")
->using(EventArtist::class);
}class EventArtist extends Pivot
{
public $table = "music_event_artist";
protected $fillable = ['artist_id','music_event_id'];
}protected static string $relationship = 'artists';
return $form
->schema([
Forms\Components\Select::make('artists')
->label('Event Artist')
->options(Artist::orderBy('name')->get()->pluck('name','id'))
->searchable(),
]);Duplicate entry '' for key 'code'
insert into artists () values ()$e = MusicEvent::find(1234);
= App\Models\MusicEvent {#7128
id: 1234,
description: "Test data here",
artists: Collection {#7106
all: [
App\Models\Artist (etc),
pivot: App\Models\EventArtist...
},
],
},
}
$e2 = Artist::find($e->artists[0]->id);
= App\Models\Artist {#7108
id: 6789,
code: "jado",
name: "Jane Doe",
}