public function propertyListener($event)
 {
     $property = $event->property;
     if ($event->type == 'new') {
         //Find admin
         $administratorRole = Role::where('slug', 'administrator')->first();
         $users = $administratorRole->users;
         $sendToEmails = $users->pluck('email')->all();
         //Find property manager in that province
         $propertyManagers = User::whereHas('roles', function ($query) {
             $query->where('slug', 'property_manager');
         })->whereHas('profile', function ($query) use($property) {
             $query->where('province', '=', $property->province);
         })->get();
         $sendToEmails = array_merge($sendToEmails, $propertyManagers->pluck('email')->all());
         ProjectHelper::sendMail($sendToEmails, 'New Property: ' . $property->property_name, 'admin.emails.property.new', ['property' => $property]);
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(ReferralInformationFormRequest $request)
 {
     $user = Auth::user();
     $referralInformation = new ReferralInformation();
     $referralInformation->fill($request->all());
     $referralInformation->user()->associate($user);
     $referralInformation->save();
     $messageVars = ['referralInformation' => $referralInformation];
     Mail::send('frontend.emails.new_referral_information', $messageVars, function ($m) use($referralInformation) {
         $m->from(config('app.contact_from_email'), config('app.contact_from_name'));
         $sendToEmails = config('app.contact_destination');
         //Find property manager in that province
         $propertyManagers = User::whereHas('roles', function ($query) {
             $query->where('slug', 'property_manager');
         })->whereHas('profile', function ($query) use($referralInformation) {
             $query->where('province', '=', $referralInformation->province);
         })->get();
         foreach ($propertyManagers as $propertyManager) {
             $sendToEmails[] = $propertyManager->email;
         }
         $m->to($sendToEmails)->subject('New Referral Listing Information');
     });
     return redirect()->route($user->backendAccess . '.referrals.index')->with('messages', ['Terima kasih untuk referensi properti kamu. Kami akan segera melakukan follow-up kepada Owner properti ini.']);
 }
 public function findAutocomplete(Request $request)
 {
     $roles = $request->get('roles', ['authenticated_user']);
     $term = $request->get('term', '');
     $return = [];
     if (strlen($term) >= 2) {
         $qb = User::whereHas('profile', function ($query) use($term) {
             $query->where('first_name', 'LIKE', '%' . $term . '%')->orWhere('last_name', 'LIKE', '%' . $term . '%')->orWhere('email', 'LIKE', '%' . $term . '%');
             //->orWhere('username', 'LIKE', '%'.$term.'%');
         });
         $qb->whereHas('roles', function ($query) use($roles) {
             $query->whereIn('slug', $roles);
         });
         $results = $qb->get();
         foreach ($results as $result) {
             $return[] = ['label' => $result->username . ' - ' . $result->profile->first_name . ' ' . $result->profile->last_name . ' (' . $result->email . ')', 'value' => $result->email];
         }
     }
     return response()->json($return);
 }