首页 > 后端开发 > php教程 > Laravel 5.3报错:`Creating default object from empty value`

Laravel 5.3报错:`Creating default object from empty value`

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
发布: 2016-10-11 14:02:12
原创
2400 人浏览过

这是代码:

ActivationService.php

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

<code>    <?php namespace App;

     

     

    use Illuminate\Mail\Mailer;

    use Illuminate\Mail\Message;

     

    class ActivationService

    {

     

        protected $mailer;

     

        protected $activationRepo;

     

        protected $resendAfter = 24;

     

        public function __construct(Mailer $mailer, ActivationRepository $activationRepo)

        {

            $this->mailer = $mailer;

            $this->activationRepo = $activationRepo;

        }

     

        public function sendActivationMail($user)

        {

     

            if ($user->activated || !$this->shouldSend($user)) {

                return;

            }

     

            $token = $this->activationRepo->createActivation($user);

     

            $link = route('user.activate', $token);

            $message = sprintf('Activate account <a href="%s">%s</a>', $link, $link);

     

            $this->mailer->raw($message, function (Message $m) use ($user) {

                $m->to($user->email)->subject('Activation mail');

            });

     

     

        }

     

        public function activateUser($token)

        {

            $activation = $this->activationRepo->getActivationByToken($token);

     

            if ($activation === null) {

                return null;

            }

     

            $user = User::find($activation->user_id);

            //下面这行是53行.

            $user->activated = true;

     

            $user->save();

     

            $this->activationRepo->deleteActivation($token);

     

            return $user;

     

        }

     

        private function shouldSend($user)

        {

            $activation = $this->activationRepo->getActivation($user);

            return $activation === null || strtotime($activation->created_at) + 60 * 60 * $this->resendAfter </code>

登录后复制

错误信息:

1

2

<code>    ErrorException in ActivationService.php line 53:

    Creating default object from empty value</code>

登录后复制

53行的位置在代码中有注释,代码是$user->activated = true;

问题:
上面的代码如何解决这个错误?

相关标签:
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
Laravel Space/laravel-backup 无法安装
来自于 1970-01-01 08:00:00
0
0
0
Laravel 5.1 登录 laravel 自带的 没有啦
来自于 1970-01-01 08:00:00
0
0
0
composer安装laravel安装不上
来自于 1970-01-01 08:00:00
0
0
0
为什么thinkphp比laravel性能好?
来自于 1970-01-01 08:00:00
0
0
0
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板