Level 15
Use the exists validation rule. Something like this perhaps.
'store_id' => 'exists:stores,id'
Or use the model instead of the column name.
'store_id' => 'exists:App\Models\Store,id'
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, when an admin creates a store the store_id field can be null but if the admin gives a store_id I want to add it to my coupon model. like $coupon->store_id = $request->store_id. But I want to check if the store exists with that id. I can do it by saying store where id == store_id but is there any way to do it with $request->validate?
Use the exists validation rule. Something like this perhaps.
'store_id' => 'exists:stores,id'
Or use the model instead of the column name.
'store_id' => 'exists:App\Models\Store,id'
Please or to participate in this conversation.