I'm using laravel 4.2. And I have this strange error.
All I'm trying to do is pass this object of User
(Eloquent
model) to the method scopeSendTo
of EmailVerification
model; and came across this strange error which I can't figure out.
Here's my code:
class EmailVerification extends Eloquent
{
...
public function scopeSendTo(User $user, $type)
{
$token = Str::slug(microtime(true).Hash::make(Str::random(20)));
$verification = new EmailVerification([
'token' => $token,
'type' => $type,
]);
$user->verifications()->save($verification);
Mail::send('emails.verification', ['verification' => $verification], function ($message) {
$name = $user->profile ? $user->profile->first_name : '';
$message->to($user->email, $name)->subject('Account Verification');
});
...
}
...
}
I'm trying to use this method like this:
$user = User::find($userId);
EmailVerification::sendTo($user, 'signup');
But it throws this error:
I even tried doing dd(get_class($user))
which confirms that the object passed is an User
object and strictly not an instance of Illuminate\Database\Eloquent\Builder
; but I can't figure out what is the problem here.