Support the ongoing development of Laravel.io →
Eloquent
Last updated 2 years ago.
0

first Unknown column 'assignable_table.assignable_id'. does this column exist?

is model TeaserAssign using the table assignable_table ?

if yes then looks like your hasMany method is wrong ?

$this->hasMany('App\Models\TeaserAssign', 'id', 'local_key');
0
Solution

Assuming the relationship is setup correctly you can do a whereHas to check for existence of a relationship with conditions.

public function scopeAssigned($query, $iAssignedId)
{
    return $query->whereHas('assign', function ($q) use ($iAssignedId) {
        $q->where('assignable_id', $iAssignedId);
    });
}
Last updated 8 years ago.
0

Thx for the answeres... whereHas was exactly what i needed :)

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.