public function accept(Request $request) { try { $this->validate($request, ['user_id' => 'required|exists:users,id']); $userID = $request->input('user_id'); $user = User::find($userID); //check if the user has been selected to be a VIP if ($this->isElegibleToVIP($userID)) { $vip = new Vip(); $vip->makeVip($userID); // Invio email Mail::send('emails.vip', ['user' => $user], function ($message) use($request) { /** * @var \Illuminate\Mail\Message $message */ $message->from(Config::get('mail.from.address'), Config::get('mail.from.name'))->to("*****@*****.**")->subject('VIP title'); }); } } catch (ValidationException $e) { $errors = $e->getErrors(); return parent::response(['validation' => false, 'errors' => $errors]); } return parent::response(['success' => true]); }
public function getCustom() { return $this->hasOne(Vip::className(), ['custom_id' => 'custom_id']); }