Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

RatulSaqibKhan/emoji-calculator-laravel

1 stars
2 code files
View RatulSaqibKhan/emoji-calculator-laravel on GitHub

app/Rules/OperandRule.php

Open in GitHub
use 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 GitHub
use 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',
];
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.