I have this validation rule on POST
request method inside a controller:
class CreateOrderController extends Controller
{
public function create(Request $request)
{
$this->validate($request, [
'store_id' => $request->order_type === OrdersTypeConstants::P2P ? "" : "required|" . 'exists:stores,id',
'p2p_type' => [Rule::in([OrdersTypeConstants::P2PCOURIER, OrdersTypeConstants::P2PPURCHASE])],
'items' => 'required_if:p2p_type,'.OrdersTypeConstants::P2PPURCHASE.'|array',
'items.*.id' => 'nullable|numeric',
'items.*.quantity' => 'nullable|integer|min:1',
'items.*.adjustment' => 'nullable|numeric',
'items.*.image' => 'nullable|string',
'items.*.addons' => 'array',
'items.*.reward_applied' => 'boolean',
'items.*.replacement_strategy.type' => [
'string',
Rule::in([ItemReplacementStrategyConstants::REMOVE,ItemReplacementStrategyConstants::BEST_MATCH, ItemReplacementStrategyConstants::SPECIFIC])
],
'items.*.replacement_strategy.quantity' => 'integer|min:1',
'items.*.replacement_strategy.item_id' => 'numeric',
'address_id' => 'exists:addresses,id,user_id,' . $client_id,
'address_id_p1' => 'exists:addresses,id,user_id,' . $client_id,
'use_cash_deposit' => 'boolean',
]);
Sometime it returns The store id field is required
even if it is actually being sent as you can see here in the error log:
It is only happening randomly -not consistently- only on production environment, reported only on firebase.
Why could that be happening?
validate
method, the base Controller in your application uses theValidatesRequest
trait – SynesthesiaOrdersTypeConstants::P2P
? – Mexican