dongwuzun4630 2015-03-24 02:42
浏览 119

Laravel5:在雄辩的模型上调用静态方法不起作用

I have a static method in User model.

namespace Tol;
...
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
    ...

    public static function signup(array $data)
    {
        $user = new User([
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
            'username' => $data['username'],
            'type' => $data['type'],
        ]);

        $user->save();

        if ($user && $user->id) {
            $profile = new UserProfile([
                'first_name' => trim($data['first_name']),
                'last_name' => trim($data['last_name']),
                'gender' => $data['gender'],
            ]);

            $user->profile()->save($profile);

            EmailVerification::sendTo($user, 'signup');
        }

        return $user;
    }
    ...

}

And I'm trying to call call this method simply from my controllers. like this

$user = User::signup($input);

And it throws error like this: enter image description here

I don't know why it is referring it as a method on the Builder class. The code is very simple and everything was working when it was Laravel 4.

Please help. thanks

  • 写回答

1条回答 默认 最新

  • douqian2524 2015-03-24 05:10
    关注

    your code should have no problem, im afraid the problem is in your auth.php file, please ensure

    'model' => 'App\User',
    

    is set it to your model file in your case

    'model' => 'Tol\User',
    

    and to ensure your calling the right file you might want to give this a try

    \Tol\User::signup($array);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)