-
app/Rules/OperandRule.php
Open in GitHubuse Illuminate\Contracts\Validation\Rule; class OperandRule implements Rule { public function passes($attribute, $value) { $accepted_values = ['addition', 'subtraction', 'multiplication', 'division']; return in_array(strtolower($value), $accepted_values) ? true : false; } public function message() { return 'The given input is not valid!'; } }
-
app/Http/Requests/CalculatorRequest.php
Open in GitHubuse App\Rules\OperandRule; use Illuminate\Foundation\Http\FormRequest; class CalculatorRequest extends FormRequest { // public function rules() { return [ 'input1' => 'required|numeric', 'operand' => ['required', 'string', new OperandRule], 'input2' => 'required|numeric', ]; } }