I tried $this->id
but it returns nothing with artisan tinker:
class Part extends Model
{
...
public function inv(): BelongsTo
{
echo "foon";
echo $this->id . "n";
return $this->belongsTo(
Inv::class,
'surv_id',
'surv_id'
);
}
}
2
Answers
If you’re trying to debug relationship, best way is to install
laravel/telescope
, (https://laravel.com/docs/10.x/telescope) in that way you can view what’s happening when you query your relationship.One way to test the primaryKeys when debugging is try putting absurd column name like
survvvvvvv_id
just to see what’s happening.As you said in a comment you want to filter
Inv
model records againstuser_id
in relation. The solution I found is using raw query with relation.I hope that will work for you.