Laravel 5.1 - Mail 函数中的未定义变量

Laravel 5.1 - undefined variable inside Mail function

我在 OfferController 中有这个存储方法:

 public function store(Requests\OfferRequest $request)
    {

            $offer = new Offer($request->all());

            Auth::user()->offer()->save($offer);

            $maxoffer =  Maxoffer::where('article_id', $request->input('article_id'))
                    ->where('start', Carbon::createFromFormat('m/d/Y h:i a', $request->input('start')))
                    ->first();

                    //dd($maxoffer->article()->first()->user->name);
   if($maxoffer == null)
    {
      Auth::user()->maxoffer()->create($request->all());
    }
    else
    {
      if($maxoffer->price < $request->input('price'))
      {
        $user = Auth::user();

        Mail::send('emails.newoffer', compact('user', 'maxoffer'), function ($m) use ($user) {

        $m->from($maxoffer->article()->first()->user->email, $maxoffer->article()->first()->user->name);
        $m->to($maxoffer->user()->first()->email, $maxoffer->user()->first()->name)->subject('Someone have the bigger offer than you');

        $key = '';
        $newOffer = Maxoffer::where('id', $maxoffer->id)
                    ->update(['price'=>$request->input('price'),'user_id'=>Auth::user()->id, 'key'=>$key, 'provera'=>$request->input('provera')]);


       });
      }
    }

        Alert::success('Keep looking for best rates. Good luck...', 'Thanks for bidding!')->persistent("Close");


        return Redirect::back();

    }

所以如果 maxoffer 不为空并且如果 maxoffer<request->input('price') 那么我需要更新一行并且效果很好,但我还需要发送 MAIL 以前的用户在新的 maxoffer 之前发布了 maxoffer 但在 MAIL 函数中我得到的只是:

未定义变量:maxoffer

这里有什么问题?为什么 maxoffer 未定义?

将$maxoffer 传递给函数闭包。使用($用户,$maxoffer)

 Mail::send('emails.newoffer', compact('user', 'maxoffer'), function ($m) use ($user, $maxoffer) {

    $m->from($maxoffer->article()->first()->user->email, $maxoffer->article()->first()->user->name);
    $m->to($maxoffer->user()->first()->email, $maxoffer->user()->first()->name)->subject('Someone have the bigger offer than you');

    $key = '';
    $newOffer = Maxoffer::where('id', $maxoffer->id)
                ->update(['price'=>$request->input('price'),'user_id'=>Auth::user()->id, 'key'=>$key, 'provera'=>$request->input('provera')]);


   });