Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel登录和注册,用户不会进入数据库_Php_Laravel - Fatal编程技术网

Php Laravel登录和注册,用户不会进入数据库

Php Laravel登录和注册,用户不会进入数据库,php,laravel,Php,Laravel,所以,我尝试使用Laravel Framwork做一个登录和注册系统。当我运行它时,我没有得到任何错误,但是当我试图创建一个用户时,它不会进入数据库。 这是我的功能 public function postRegister() { $input = Input::all(); $rules = array("username" => "required|unique:users|email", "password" => "required"

所以,我尝试使用Laravel Framwork做一个登录和注册系统。当我运行它时,我没有得到任何错误,但是当我试图创建一个用户时,它不会进入数据库。 这是我的功能

 public function postRegister()
    {
        $input = Input::all();
        $rules = array("username" => "required|unique:users|email", "password" => "required");
        $v = Validator::make($input, $rules);
        if($v->passes())
        {
            $user = new User();
            $password = $input["password"];
            $password = Hash::make($password);
            $user = new User();
            $user->username = $input["username"];
            $user->email = $input["email"];
            $user->password = $password;
            $user->save();

            return Redirect::to("login");
            echo 'Succes, now you can log in!';

        } else{
            return Redirect::to("register");
            echo 'Someting went wrong, try again!';
        }
    }
在这里您可以看到我的
register.blade

    <!doctype html>
    <html>
    <head>
        <title>Register</title>
    </head>
    <body>

        {{ Form::open(array('url' => 'register')) }}
            <h1>Register</h1>

            <!-- if there are login errors, show them here -->
            @if (Session::get('registerError'))
            <div class="alert alert-danger">{{ Session::get('registerError') }}</div>
            @endif

            <p>
                {{ $errors->first('username') }}
                {{ $errors->first('email') }}
                {{ $errors->first('password') }}
            </p>
            <p>
                {{ Form::label('username', 'Username') }}
                {{ Form::text('username', Input::old('username'), array('placeholder' => 'Choose Username')) }}
            </p>


            <p>
                {{ Form::label('email', 'Email Address') }}
                {{ Form::text('email', Input::old('email'), array('placeholder' => 'awesome@awesome.com')) }}
            </p>

            <p>
                {{ Form::label('password', 'Password') }}
                {{ Form::password('password') }}
            </p>

            <p>{{ Form::submit('Register') }}</p>
            <p>{{HTML::link("login", "Back to login")}}</p>
        {{ Form::close() }}

    </body>
    </html>

登记
{{Form::open(数组('url'=>'register'))}
登记
@if(会话::get('registerError'))
{{Session::get('registerError')}
@恩迪夫

{{$errors->first('username')}
{{$errors->first('email')}
{{$errors->first('password')}

{{Form::label('username','username')} {{Form::text('username',Input::old('username'),array('placeholder'=>'Choose username'))}

{{Form::label('email','email Address')} {{Form::text('email',Input::old('email'),array('placeholder'=>'awesome@awesome.com')) }}

{{Form::label('password','password')} {{Form::password('password')}

{{Form::submit('Register')}

{{HTML::link(“登录”,“返回登录”)}

{{Form::close()}}

也许我只是错过了一些东西

删除双
$user=new user()当然啦!但它仍然无法解决问题,请使用
print\r(input::all())
(记住注释掉返回值)打印输出输入,并查看是否将post数据传递给该函数。是的,控制器是错的,如果不是的话,视图中出现了一些错误。是的,好的,仍然没有解决用户在我注册时没有进入数据库的问题。你在返回后回显内容,这将永远看不到曙光。return语句告诉PHP结束此方法的执行并继续执行,因此如果验证出现错误,您永远不会知道。