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

davy_yg's avatar
Level 27

has

Cek this code:

$seller = Seller::has('transactions')->findOrFail($id);

has('transaction') is it checking the existance of transactions table?

0 likes
6 replies
bobbybouwmann's avatar

@davy_yg It's not checking for existence of the table. It's checking if the seller has any known relationship with transactions. If there is a relation (1 or more) with transactions the Seller is returned. In your case this would return just one Seller object.

If there is no relation with transactions the Seller is not returned. In your case that would throw a ModelNotFoundException.

If you also want to load the transactions data on the seller object you can do something like this

$seller = Seller::has('transactions')->with('transactions')->findOrFail($id);
bobbybouwmann's avatar

@picasso1 Don't be a dick! It can be tough to learn all these new concepts and Eloquent if you're new to the framework. We have a forum for these kind of questions right?

chatty's avatar

No. the first thing i would do is google. but i thought the comment was mean so deleted it

davy_yg's avatar
Level 27

So it's checking if there is a transaction row connected to the transaction table?

ftiersch's avatar
ftiersch
Best Answer
Level 28

No, it gives you all sellers that have at least one row in the transactions table they are connected to. Transactions are in the transactions table anyway.

The 'transactions' in the function is not the table name but the name of the relationship method on the Seller class.

Please or to participate in this conversation.