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:
what is problem here? Why maxoffer is undefined?