Laravel 4与阵列的关系

时间:2014-09-05 20:43:49

标签: php laravel laravel-4 relationship php-5.3

我试图通过建立与变量的关系来获取数组中的字段,并且我得到的错误是" Undefined属性:Illuminate \ Database \ Eloquent \ Builder :: $ email&#34 ;, 任何帮助都会很棒,非常感谢。我的控制器在下面。

else {
        $email = Input::get('email');
        $username = Input::get('Username');
        $password = Input::get('password');
        $code = str_random(60);
        $Passed = User::Insert(array(
            'email' => $email,
            'username' => $username,
            'password' => Hash::make($password),
            'code' => $code,
            'active' => 0,
            'groups' => 0
            ));

            Mail::send('emails.auth.Email',array(
                'link' => URL::route('account-activate', $code),
                'Username' => $username),
            function($message) use ($Passed) {
                $message->to($Passed->email, $Passed->username)->subject('activation');
            });
            return Redirect::route('home')->with('global', 'Hello world');      
    }

1 个答案:

答案 0 :(得分:0)

问题是$Passed->email给出了这个错误,因为$Passed不是模型或集合,但仍然是查询构建器,可能是因为插入模型不能完成整个工作插入记录并返回新模型。所以,不应该是:

$Passed = User::create(array(
        'email' => $email,
        'username' => $username,
        'password' => Hash::make($password),
        'code' => $code,
        'active' => 0,
        'groups' => 0
        ));