1

I don't know how to get the query string array to validate in Laravel Validation.

here is my code

 public function addUserByAdmin(Request $request){
    $this->validate($request,[
        'name' => 'required',
        'fullname' => 'required',
        'password' => 'required',
        'position' => 'required',
        'phone' => 'required'
    ]);
        $uesrAction = new UserAction($this->repository);
        $user = $uesrAction->addUser($request->input('phone'),$request->input('password'),$request->input('name'),$request->input('fullname'),$request->input('position'));
        if($user){
            return response()->json(['success' => 'success','user'=>$user]);
        }
        return response()->json(['success' => 'fail']);
}

but validation doesn't work.Then I tried Validation::make() method and also didn't work.

My URL be like

http://localhost:8000/admin/users/add-user?phone=abcdefg&password=erer&name=ere&fullname=rere&position=343
3
  • what's your exact problem?? Validation should works fine here. Commented Nov 26, 2017 at 18:12
  • 1
    what do you mean by 'doesnt work'? what are you expecting to happen and what is actually happening? Commented Nov 27, 2017 at 2:14
  • 1
    password in the URL? Commented Dec 10, 2019 at 14:15

1 Answer 1

1

If you are using laravel 5.5, change your code as follows:

public function addUserByAdmin(Request $request){

    $validatedData = $request->validate([
        'name' => 'required',
        'fullname' => 'required',
        'password' => 'required',
        'position' => 'required',
        'phone' => 'required'
    ]);

    // ...
}

One of the features that was added in this update is that other way to use the validate() method:

More info:

https://laravel.com/docs/5.5/validation#quick-writing-the-validation-logic https://laravel.com/docs/5.5/releases

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.