方法验证不存在

时间:2017-09-12 19:40:03

标签: php laravel-5.3

我尝试了其他人建议的其他修复程序,但它们没有用。我真的不知道为什么这不起作用,一直在寻找两个小时。

<?php

namespace App\Http\Controllers;

use App\User;

use App\Http\Controllers\Controller as Controller;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Request;

class RegisterUser extends Controller
{




    use ValidatesRequests;

    public function __construct()
    {
        $this->middleware('guest');
    }

    public function store(Request $request)
    {

        $request->validate([
            'email' => 'required|string|email|max:255|unique:users',
            'password' => 'required|string|min:6|confirmed',
            'passwordr' => 'required|string|min:6',
        ]);



        $name = 'NoName';
        $email = $request->input('email');
        $password = bcrypt($request->input('password'));

        $user = new \App\User();
        $user->name = $name;
        $user->password = $password;
        $user->email = $email;
        $user->save();

        return redirect()->action('HomeController@index');
    }
}

我不知道什么是错的

1 个答案:

答案 0 :(得分:2)

当您向某个类添加特征时,该特征的方法可在该类中使用。所以你需要做的是: -

$this->validate($request, [
  'email' => 'required|string|email|max:255|unique:users',
            'password' => 'required|string|min:6|confirmed',
            'passwordr' => 'required|string|min:6',
        ]);

instead of 

$request->validate([
            'email' => 'required|string|email|max:255|unique:users',
            'password' => 'required|string|min:6|confirmed',
            'passwordr' => 'required|string|min:6',
        ]);