Search code examples
phplaravellaravel-5.5laravel-5.6

After submitting a form, I get "Method Illuminate\Validation\Validator::validate255 does not exist."


After submitting a form, I get this error "Method Illuminate\Validation\Validator::validate255 does not exist.",

I have checked functions where i have validating, and can't even find what the problem is?

Here is my first store function:

 public function store(Request $request)
{
    // Validate form

    $this->validate($request, [
        'name' => 'required|255',
        'email' => 'required|email|unique:users'
    ]);

    // Generate password
    if(Request::has('password') && !empty($request->password)){
        $password = trim($request->password);
    } else{
        # set the manual password
        $length = 10;
        $keyspace = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
        $str = '';
        $max = mb_strlen($keyspace, '8bit') - 1;

    for ($i = 0; $i < $length; ++$i) {
        $str .= $keyspace[random_int(0, $max)];
    }
        $password = $str;
    }

    $user = new User();

    // Insert User's data into database
    $user->name = $request->name;
    $user->email = $request->email;
    $user->password = Hash::make($password);


    if($user->save()){
        return redirect()->route('users.show', $user->id);
    } else{
        Session::flash('danger', 'Sorry, a problem occured while creating this user.');
        return redirect()->route('users.create');
    }

}

And, here is update function for editinig user:

public function update(Request $request, $id)
{
    $this->validate($request, [
        'name' => 'required|max:255',
        'email' => 'required|email|unique:users,email,'.$id
    ]);

    $user = User::findOrFail($id);
    $user->name = $request->name;
    $user->email = $request->email;

    if($request->password_options == 'auto'){
        # set the manual password
        $length = 10;
        $keyspace = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
        $str = '';
        $max = mb_strlen($keyspace, '8bit') - 1;

    for ($i = 0; $i < $length; ++$i) {
        $str .= $keyspace[random_int(0, $max)];
    }
        $password = $str;

    } elseif($request->password_options == 'manual'){
        $user->password = Hash::make($request->password);
    }

    if($user->save()){
        return redirect()->route('users.show', $id);
    } else{
        Session::flash('danger', 'There was a problem saving the updated user info to the database. Please, try again.');
        return redirect()->route('users.edit', $id);
    }
}

I don't think there is a problem with front-end, but if that can be for some reasone, i'll update the post.


Solution

  • chance 'name' => 'required|255', to 'name' => 'required|max:255',