Hi how can I check for Eloquent polymorphic relationship already exist?
For example, I want to prevent data with same upload_id, attachable_id and attachable_type from getting store in the attachments table (refer to the highlight)
What I have try but did not get correct count of relationship exist:
//get count of attachment
$application->has('attachments')->count()
You can just query the related attachments for that upload_id
:
$hasAttachments = $application->attachments()
->where('upload_id', $upload_id)
->count() > 0;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With