LoginSignup
5
4

More than 5 years have passed since last update.

laravel5でMailクラスにメールアドレス等の引数渡すときのTips

Posted at

Laravel5のMailクラス便利ですよね。

公式ドキュメントだと、こんな感じで書いてあります。
http://readouble.com/laravel/5/0/0/ja/mail.html

Mail::send('emails.welcome', ['key' => 'value'], function($message)
{
    $message->to('foo@example.com', 'John Smith')->subject('Welcome!');
});

この
'foo@example.com', 'John Smith'あたりは変数で行きたいところです。

PHPの無名関数に引数を渡すときは、useを使うのだそうです。


$user = $this->user->whereId('hogehoge')->first();

Mail::send('emails.welcome', ['key' => 'value'], function($message) use($user)
{
    $message->to($user->email, $user->name)->subject('Welcome!');
});
5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4