Friday, March 3, 2017

Laravel get user phone from db

I got users table with phone row. I'm trying to send SMS then user is activated like that:

      public function activate($token)
    {
        User::whereActivationToken($token)->firstOrFail()->confirmEmail();
      $phone = $this->user->phone;

        flash()->success(trans('frontend.account.activated'));

        if (Auth::check()) {
            return redirect()->route('account.home');
        } else {
            return redirect()->route('auth.login');
Sms::send("activated!", function($sms) {
    $sms->to(['$phone']); # The numbers to send to.
});
        }
    }
}

But i'm getting error, Trying to get property of non-object. Whats wrong? Thanks for answers guys and please dont be mad, i'm new on laravel.



via ром Макаров

Advertisement