How to compare the request input to the database like
- exists:users, id and compare the request input to users table on the id column.
How can I compare the request input greater than, less than from database for example:
my money column got 5, and I want to withdraw 6,
the validation must be less than equal 5; if I input 6, then it will error.
so it will be (my_database_variable >= request_input).
EDIT 1
I think I'm not using the custom validation cause it work on max.
But how to pass the parameter on FormRequest(TransactionRequest) ?
public function rules()
{
return [
"action" => "required|in:kylder,koul",
"amount" => "required|numeric|min:100|max".$max_amount, //<---- how to pass this from controller
"currency" => "required|in:kylder,koul",
"receiver_id" => "required|exists:users,id",
"message" => "sometimes|nullable"
];
}
and in my controller, I am using this to validate
public function transaction(TransactionRequest $request)
{
$max_variable = 20; // <---- I want to pass this on rule()
$response = $request->validated();
...
}
how do I pass the variable of $max_amount into rule()?