/Invitation.php Secret
Last active
February 22, 2016 15:32
Dealing with Dependencies in Active Record Models — Option #1: Using a facade/service locator/global access
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Invitation extends Model | |
{ | |
public function user() | |
{ | |
return $this->belongsTo(User::class, 'invited_by'); | |
} | |
public function send() | |
{ | |
Mail::send('emails.invitation', ['invited_by' => $this->user], function ($m) { | |
$m->to($this->recipient)->subject("You've been invited to my app!"); | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class InvitationsController extends Controller | |
{ | |
public function store() | |
{ | |
$invitation = Invitation::create([ | |
'recipient' => request('recipient'), | |
'invited_by' => auth()->user()->id, | |
]); | |
$invitation->send(); | |
return response('', 204); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment