With the Laravel 5.3 Notification feature, I see that the notifications are sent to users like this:
$user->notify(new InvoicePaid($invoice));
Where I believe $user
is the notifiable entity. What if I want to send notifications to users who doesn't have an account yet? In my app, users send invitation to their friends to join. I am trying to use Laravel's Notification to send the invite code to users who don't have an account yet.
When users invite someone, their data is stored in Invite Model like this:
class Invite extends Model
{
protected $table = 'invites';
protected $fillable = array('name', 'email', 'invite_code', 'expires_at', 'invited_by');
protected $dates = ['expires_at'];
}
I thought I can use notify to send notifications to the Invite model like this:
$invite = Invite::find($inviteId);
$invite->notify(new InvitationNotification(ucfirst($invite->name), $invite->invite_code, $invite->expires_at));
But the above doesnt work. I get the error:
Call to undefined method Illuminate\Database\Query\Builder::notify()
So my question is:
Am I able to send Notification only to User Model?
Is there a way to send Notifications to new users who doesnt have an account yet?
Is my only choice is to use Laravel's Mailable class instead of Notification in these cases?