Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RequestAbstract] validated() method causes the validation to be called again. #19

Open
Slisarenko opened this issue Aug 31, 2022 · 0 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@Slisarenko
Copy link
Contributor

Lumen Version: 8.x
PHP Version: 7.4

Description:
The problem is getting the retrieve the validated input data with method validated(). When it is called, it re-initiates the request validation.

Steps To Reproduce:

  1. Controller:
use App\Http\Requests\UserRequest;

class UserController extends Controller
{
    public function sandbox(UserRequest $request)
    {
        return response()->json($request->validated());
    }
}
  1. RequestAbstract:
use Pearl\RequestValidate\RequestAbstract;
use Illuminate\Validation\Rule;

class UserRequest extends RequestAbstract
{
    public function rules()
    {
        return [
	    'full_name' => 'required|string|max:50',
	    'phone' => [
	        'required',
	        'max:50',
	        'regex:/^(\+[0-9]+)$/',
	        Rule::unique('clients')->where(function($query){
	            return $query->where('account_id', auth()->user()->account_id);
	        })
	    ],
	    'email' => 'nullable|email|max:50',
	    'info' => 'max:200'
        ];
    }
}
  1. Debugbar:
    Since the rules have a check in the database, we can see a duplicated query to the database, which means that the method rules() was called twice.
    image
@Slisarenko Slisarenko changed the title [FormRequest] validated() method causes the validation to be called again. [RequestAbstract] validated() method causes the validation to be called again. Aug 31, 2022
@pearlkrishn pearlkrishn added the bug Something isn't working label Nov 28, 2022
@pearlkrishn pearlkrishn added the help wanted Extra attention is needed label Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants