Created
November 12, 2015 15:32
-
-
Save gbrock/80d351f7a28c4772a6b0 to your computer and use it in GitHub Desktop.
Laravel 5.1 example of abstracting e-mail sending into its own dedicated class
This file contains 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 | |
namespace App\Extensions; | |
use Illuminate\Support\Facades\Mail; | |
class Postmaster { | |
/** | |
* Send an e-mail to a specific user. Pass in the User object, | |
* the name of the view, any data needed by the view, and the subject. | |
*/ | |
public static function toUser($user, $view, $data, $subject = false) | |
{ | |
Mail::send($view, $data, function ($message) use ($user, $subject) { | |
if ($user->email) { | |
$message->to($user->email, $user->name)->subject($subject); | |
} else { | |
return false; | |
} | |
}); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment