必须输入值作为注册中的插入,并将值与在 laravel 4.2 中使用登录插入的值匹配


Have to input values as insert in signup and matching the values with inserted using login in laravel 4.2

大家好,他们能够简单地验证登录详细信息和注册详细信息,但无法使用 laravel 4.2 插入和获取 phpmyadmin 数据库。你能帮忙吗?

以下是我的模型代码

class Website extends Eloquent implements UserInterface, RemindableInterface 
{ 
use UserTrait,RemindableTrait;
protected $table = 'websites'; 
protected $hidden = array('password', 'remember_token');
protected $protected = array();
protected $fillable = array('name',email','username','password','confirm_password','phone');
}

这是视图文件的代码

这是查看文件

注册刀片.php

                                                {{ Form::open(array('url' => 'register')) }}    
                                                            @if($errors->has('name'))
                                                                    {{ $errors->first('name') }}
                                                                @endif                      
                                                            {{ Form::label('name', 'Name:') }}
                                                            {{ Form::text('name')  }}

                                                             @if($errors->has('username'))
                                                                    {{ $errors->first('username') }}
                                                                @endif
                                                            {{ Form::label('username', 'Username:') }}
                                                            {{ Form::text('username') }}
                                                            @if($errors->has('password'))
                                                                    {{ $errors->first('password') }}
                                                                @endif
                                                            {{ Form::label('password', 'Password:') }}
                                                                {{ Form::password('password') }}
                                                            @if($errors->has('password'))
                                                                    {{ $errors->first('confirm_password') }}
                                                                                @endif
                                                            {{ Form::label('password', 'Confirm Password:') }}
                                                            {{ Form::password('confirm_password') }}
                                                            @if($errors->has('email'))
                                                                                {{ $errors->first('email') }}
                                                                                                @endif
                                                            {{ Form::label('email', 'Email:') }}
                                                                {{ Form::text('email')  }}

                                                            @if($errors->has('phone'))
                                                                                    {{ $errors->first('phone') }}
                                                                                    @endif
                                                            {{ Form::label('phone', 'Phone:') }}
                                                            {{ Form::text('phone') }}

                                                            </div>
                                                        {{ Form::submit('Create', array('class' => 'btn btn-success')) }}

                {{ Form::close() }}

这是login.blade.php

{{ Form::open(array('url' => 'login')) }}
  <table>
     <tr>
        <td width="150px" class="table-responsive">
            {{ Form::label('username', 'Username:') }}
            {{ Form::text('username') }}
             @if($errors->has('username'))
                          <label> {{  $errors->first('username') }} </label>
             @endif
       </td>
        </tr>   
        <tr>
          <td width="150px">
            {{ Form::label('password', 'Password:') }}
            {{ Form::text('password') }}
            @if($errors->has('password'))
                          <label> {{  $errors->first('password') }} </label>
             @endif
        </td>
        </tr>
         <tr>
          <td width="150px">
        <div class="field">
            <input type="checkbox" name="remember"  id="remember"> 
            <label for="remember"> 
                Remember me
                </td>
        </tr>
        </div>
        <tr>
        <td>
            {{ Form::submit('Login', array('class' => 'btn btn-primary')) }}
       </td>
</tr>
</table>    
@if( $errors->count() > 0 )
    <p>The following errors have occurred:</p>
    <ul id="form-errors">
        {{ $errors->first('username', '<li>:message</li>') }}
        {{ $errors->first('password', '<li>:message</li>') }}
        {{ $errors->first('password_confirmation', '<li>:message</li>') }}
    </ul>   
@endif{{ Form::close() }}

这是我的功能控制器代码

网站控制器.php

<?php
    class WebsiteController extends BaseController {
            public function index()
                        {
                            return View::make('websites.index',compact('websites'));
                        }

            public function login()
                        {
                             return View::make('websites.login');
                        }
            public function signup()
                        {
                                return View::make('websites.signup');
                        }

            public function show()
                        {
                                                 $input=Input::all();
                                                 $messages = array('username.required' => 'Please enter your username','password.required' => 'You have to set a password');
                                                 $rules = array(  'username'  => 'required|alpha-num','password'  => 'required');
                                                 $validator = Validator::make($input,$rules,$messages);
                                    if ($validator->fails()) {
                                                                      print_r($input);
                                                                      echo 1;
                                                                      return Redirect::to('login')->withErrors($validator);
                                                             }

                                                        else
                                                             {
                                                                  return Redirect::to('websites')
                                                                  ->with('message', 'Your account has been created, please login');                                                                   print_r($input);      
                                                             }

                     }
            public function store()
            {
                        $input=Input::all();
                         $messages = array(
                                                            'name.required' => 'Please enter your name',
                                                            'email.required' => 'your email address required',
                                                            'username.required' => 'Please enter your username',
                                                            'password.required' => 'You have to set a password',
                                                            'confirm_password.required' => 'Write again your password',
                                                            'confirm_password.matchpass' => 'The two passwords does not match');
                                  $rules = array(
                                                            'name'=>'required|alpha',                     
                                                            'username'  => 'required|alpha-num',
                                                            'password'  => 'required',
                                                            'confirm_password'=>'required',
                                                            'email'     => 'required|email',
                                                            'phone'=>'required|numeric'
        );

                         $validator = Validator::make($input,$rules,$messages);
                                    if ($validator->fails()) {
                                                                  print_r($input);
                                                                echo 1;
                                                                 return Redirect::to('register')->withErrors($validator)->withInput();
                                    }
                                                        else
                                                             {
                                                                        $user = new Website();
                                                                        $user->username =$input['username'];
                                                                        $user->email = $input['email'];
                                                                        $user->password = $input['password'];
                                                                        $user->name = $input['name'];
                                                                        $user->phone =$input['phone'];
                                                                        return Response::json(array('success' => true), 200);
                                                                        return Redirect::to('login')
                   ->with('global', 'Your account has been created! We have sent an email to activate your account');
//                                                                      }
                                                                                                                                    }

        }
        }
?>

您只是忘记在store方法中save数据。

加:

$user->save();

自:

$user = new Website();
$user->username =$input['username'];
$user->email = $input['email'];
$user->password = $input['password'];
$user->name = $input['name'];
$user->phone =$input['phone'];

最终结果:

$user = new Website();
$user->username =$input['username'];
$user->email = $input['email'];
$user->password = $input['password'];
$user->name = $input['name'];
$user->phone =$input['phone'];
$user->save();

要在index method中获得所有结果,您需要在返回之前添加以下代码:

$websites = Website::all(); 

最终结果:

public function index()
{
    $websites = Website::all();
    return View::make('websites.index',compact('websites'));
}

另外,您的model有一个错误,在这一行您缺少一个apostrophe,这是正确的:

protected $fillable = array('name','email','username','password','confirm_password','phone');