1

I have this store method inside 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();

    }

so if maxoffer is not null and if maxoffer<request->input('price') then I need to update an row and that work nice, but also I need to send MAIL to previous user which was posted maxoffer before new maxoffer but inside MAIL function I get just:

undefined variable: maxoffer enter image description here

what is problem here? Why maxoffer is undefined?

1
  • Probem is only maxoffer variable - I can pass it into Mail::send ... Commented Mar 27, 2016 at 14:07

1 Answer 1

2

Pass $maxoffer to the function closure. use($user, $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')]);


   });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.