Reputation: 165
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.
Upvotes: 2
Views: 925
Reputation: 163938
Change your code to this:
$user = User::whereActivationToken($token)->firstOrFail();
$user->confirmEmail();
$phone = $user->phone;
Upvotes: 1
Reputation: 13259
Your error may be coming from this line
$phone = $this->user->phone;
$user exists nowhere in that function. Perhaps you defined it somewhere else. If that's the case, you can fix it with :
$user = User::whereActivationToken($token)->firstOrFail();
$phone = $user->phone;
Upvotes: 1