Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

YashD's avatar
Level 1

Relation Between 3 Tables

1)table = fishtype: columns id type

2)table = product columns id fishtype_id

3)table = check columns id product_id

In check index.blade I want type

Ty In Advance

0 likes
4 replies
tisuchi's avatar

You can do relationships like this way.

firshtype.php

public function product(){
    return hasMany('App\Fishtype');
}

product.php

public function check(){
    return hasMany('App\Check');
}

Now, if you need to access any fishtype, you can try-

$fishtype = Fishtype::with('product', 'product.check')->where('id', 1)->first();

//printing product details that is associated with fishtype id 1
echo $fishtype->product->fishtype_id;

//printing check 
echo $fishtype->product->check->product_id;

1 like
YashD's avatar
Level 1

@tisuchi

$fishtype = Fishtype::with('product', 'product.check')->where('id', 1)->first(); $fishtype = product.check ->product_id;

tisuchi's avatar

It should be like this-

echo $fishtype->product->check->product_id;

Instead of -

echo $fishtype = product.check ->product_id;
1 like

Please or to participate in this conversation.