Q:

Passing variables from Controller to Mailables in Laravel [php]

In my UserController I have a function 
public function userFollow($id)
    {
        $authuser = Auth::user();
        $authuser->follow($id);
        //mail goes to the followiee ($id)
        $followiee = User::where('id', $id)->first();
        $to = $followiee->email;
        Mail::to($to)->send(new MyMail);
        return redirect()->back()->with('message', 'Following User');
    }

I have also created a Mailable MyMail
class MyMail extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('emails.welcome');
    }
}

Inside my welcome email I need to access some variables like $to which is defined in the UserController
I tried the following in MyMail Mailable:
 public function build()
    {
        return $this->view('emails.welcome',['to' => $to]);
    }

But I am getting Undefined variable: to
How to pass variables from Controller to Mailables?
Update:
What I have tried so far:
UserController
Mail::to($to)->send(new MyMail($to));

MyMail
    public $to;
    public function __construct($to)
    {
        $this->to = $to;
    }

    public function build()
    {
        return $this->view('emails.welcome');
    }

Welcome.blade.php
 {{ $to }}

Error:
FatalErrorException in Mailable.php line 442:
[] operator not supported for strings

A:

One solution is to pass variables to the MyMail constructor, like this:
UserController
Mail::to($to)->send(new MyMail($to));

MyMail
public $myTo;

public function __construct($to)
{
    $this->myTo = $to;
}

public function build()
{
    return $this->view('emails.welcome');
}

Welcome.blade.php
{{ $myTo }}

Update:
As @Rahul noted in his answer, the $to property can be defined as public. And in this case the view will be populated with it automatically.
Update 2:
You just need to give a different name to your $to variable (e.g. $myTo) to distinguish it from the $to in the Mailable.php which is defined as public $to = [];.

