mardi 25 décembre 2018

Laravel - morphToMany Custom Keys

I'm in the process of trying to convert and clean up a project that had too many tables and classes doing similar functions. I'm going class by class to clean up the code and refresh the functions but one thing I need help with are the custom keys for a morphToMany function.

At the moment, I have a class called osd_detail and it has the following relationship:

public function attachments(){
    return $this->morphToMany(ClaimAttachment::class, 'attachable');
}

And then as you can see I have another class called ClaimAttachment. Well I have an attachables table with the following structure:

  • attachment_id
  • attachable_id
  • attachable_type

But at the moment, when I go to test it out, it still is looking for claim_attachment_id. At the moment, I would prefer to go about changing the foreign key for this instance. I'm not sure I'm quite on the right track and would appreciate any help anyone can give.

Thank you so much!



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2EM353L
via IFTTT

Aucun commentaire:

Enregistrer un commentaire