<?php namespace App\Rules\Order; use App\Http\Requests\Request; use Illuminate\Contracts\Validation\Rule; use Exception; class Store implements Rule { protected $request; protected $message = ''; /** * Store constructor. * @param Request $request */ public function __construct(Request $request) { $this->request = $request; } /** * @param string $attribute * @param mixed $value * @return bool * @throws Exception * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function passes($attribute, $value) { $address = $this->request->input('address', false); $shippingMethod = $this->request->input('shipping_method', false); if (getShippingMethodInstance($shippingMethod)->isAddressRequired() && !$address && empty($value)) { $this->message = __('order.address', ['field' => $attribute]); return false; } return true; } /** * Get the validation error message. * * @return string */ public function message() { return $this->message; } }