未定义的变量错误(noob问题) [英] Undefined variable error (noob question)

查看:75
本文介绍了未定义的变量错误(noob问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到



AccountController.php第47行ErrorException:

未定义变量:user



这是我的帐户控制器代码



I am getting

ErrorException in AccountController.php line 47:
Undefined variable: user

Here's my account controller code

<?php
namespace App\Http\Controllers;
use Input;
use Illuminate\Support\Facades\Redirect;
use App\User;
use Hash;
class AccountController extends Controller {
    
    public function getCreate(){
        
     return \View::make('account.create');   
    }
    
    public function postCreate(){
        
        $validator= \Validator::make(input::all(),
        array(
            'email'=>'required|max:50|email|unique:users',
            'username'=>'required|max:20|min:3|unique:users',
            'password'=>'required|min:6',
            'password_again'=>'required|same:password'
            ));
            
            if($validator->fails()){
                
                return Redirect::route('account-create')
                       ->withErrors($validator)
                       ->withInput();
                
            }else{
                
                //create account
                
                $email = Input::get('email');
                $username = Input::get('username');
                $password = Input::get('password');
                //Activation code
                $code=str_random(60);
                
                $create = User::create(array(
                    'email'=>$email,
                    'username'=>$username,
                    'password'=>Hash::make($password),
                    'code'=>$code,
                    'active'=>0
                    ));
                    if($user){
                        return Redirect::route('home')
                        ->with('global',"sent email");
                        
                        
                    }
                    }
                
            }
        
        
    }

推荐答案

validator = \Validator :: make(input :: all(),
array(
' email' => ' required | max:50 | email | unique:users'
' username' => ' required | max:20 | min:3 | unique:users'
' password' => ' required | min:6'
' password_again' => ' required | same:password'
));

if(
validator= \Validator::make(input::all(), array( 'email'=>'required|max:50|email|unique:users', 'username'=>'required|max:20|min:3|unique:users', 'password'=>'required|min:6', 'password_again'=>'required|same:password' )); if(


validator-> failed()){

return 重定向:: route(' account-create'
- > withErrors (
validator->fails()){ return Redirect::route('account-create') ->withErrors(


验证器)
- > withInput();

}其他{

// 创建帐户

validator) ->withInput(); }else{ //create account


这篇关于未定义的变量错误(noob问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆