如何在laravel 5.1中访问子函数内的父函数的参数

I have this code to send mail .

public static function sendemail($recipient,$ticketdata)  
{
    Mail::send('emails.ticketbooked', $ticketdata, function ($message) {
        $message->to($recipient)->subject('Tickets Booking Confirmation');
    });
}

When this code is executed I am getting error message that "Undefined variable: recipient"

Kindly help me correct this error.

Tezla has pointed this out, but to bring in variables from a parent function when using Mail you need to utilise use(). It isn't mentioned in the docs, but it is used in the example they provide:

public function sendEmail(Request $request, $id)
    {
        $user = User::findOrFail($id);

        Mail::send('emails.reminder', ['user' => $user], function ($m) use ($user) {
            $m->from('hello@app.com', 'Your Application');

            $m->to($user->email, $user->name)->subject('Your Reminder!');
        });
    }

In the above example, they are finding the users details with an Eloquent query and then bringing those in to the Mail process with use().

In your case, you would want to format it like so:

public static function sendemail($recipient,$ticketdata)  
{
    Mail::send('emails.ticketbooked', $ticketdata, function ($message) use($recipient) {
        $message->to($recipient)->subject('Tickets Booking Confirmation');
    });
}