FilamentF
Filamentβ€’2y ago
SirAlyon

Trouble with Relation Manager for Many-to-Many Relationship

Hello everyone, I'm experiencing issues with managing the Filament relation manager. Currently, I have two Laravel models related with a many-to-many relationship. I've followed the steps in the documentation, but I can't understand why I'm not getting any results. The manager table is not displayed in the create or edit views of the resource, and all this happens without triggering any errors. I'll paste the formatted code that's needed for reference.

I'm pretty confident the issue lies on the Filament side, as I've tested the relationship with Laravel Tinker, and it works correctly. I'm not getting any results in the edit/create views of the resource. Can anyone help me figure out what's going wrong?


KiidPdfPattern Model:
class KiidPdfPattern extends Model
{
    use HasFactory;

    public $timestamps = false;

    protected $table = 'kiid_dati_tipo';
    protected $primaryKey = 'lunivid';
    protected $guarded = [];

    public function kiidMailPdfs(): BelongsToMany
    {
        return $this->belongsToMany(KiidMailPdf::class, 'kiid_mail_pdf_kiid_dati_tipo', 'kiid_dati_tipo_lunivid', 'kiid_mail_pdf_lunivid');
    }
}


KiidMailPdf Model:
class KiidMailPdf extends Model
{
    use HasFactory;

    protected $table = 'kiid_mail_pdf';
    //protected $connection = 'palliauto';

    public $timestamps = false;
    
    protected $primaryKey = 'lunivid';
    protected $guarded = [];

    public function kiidPdfPatterns(): BelongsToMany
    {
        return $this->belongsToMany(KiidPdfPattern::class, 'kiid_mail_pdf_kiid_dati_tipo', 'kiid_mail_pdf_lunivid', 'kiid_dati_tipo_lunivid');
    } 
}


...other code in the comments! Thank you all guys! πŸ™‚
Was this page helpful?