Skip to content

Instantly share code, notes, and snippets.

@tonysm
Last active March 1, 2016 19:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonysm/4502f4eb0bad02edf441 to your computer and use it in GitHub Desktop.
Save tonysm/4502f4eb0bad02edf441 to your computer and use it in GitHub Desktop.
<?php
class Invitation
{
private $mailer;
public function __construct(Mailer $mailer)
{
$this->mailer = $mailer;
}
public function send(User $inviter, $invitee)
{
$invite = $user->invites()->create([
'invitee' => $invitee
]);
$this->mailer->send('emails.invitation', ['inviter' => $inviter], function ($m) use ($invitee) {
$m->to($invitee)->subject('You have been invited to this awesome app');
});
return $invite;
}
}
<?php
class InvitationsController extends Controller
{
public function store(Invitation $invitation)
{
$to = request()->get('invitee');
$from = auth()->user();
$invitation->send($from, $to);
}
}
<?php
class Invite extends Model
{
public function inviter()
{
return $this->hasOny(User::class);
}
}
<?php
class User extends Model
{
public function invites()
{
return $this->hasMany(Invite::class, 'inviter_id');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment