input('term')) return $result; $account_ids = ($x=Auth::user()->accounts_all)->pluck('id'); // Look for User foreach (User::Search($request->input('term')) ->whereIN('id',$x->pluck('user_id')->unique()) ->orderBy('lastname') ->orderBy('firstname') ->limit(10)->get() as $o) { $result->push(['name'=>sprintf('%s (%s) - %s',$o->name,$o->lid,$o->email),'value'=>'/u/home/'.$o->id,'category'=>'Users']); } // Look for User by their Supplier ID with some suppliers if (is_numeric($request->input('term'))) foreach (User::select(['users.*','suppliers.name AS supplier_name','supplier_user.id AS pivot_id']) ->join('supplier_user',['supplier_user.user_id'=>'users.id']) ->join('suppliers',['suppliers.id'=>'supplier_user.supplier_id']) ->whereIN('user_id',$user_ids) ->where('supplier_user.id','like','%'.$request->input('term').'%') ->orderBy('lastname') ->orderBy('firstname') ->limit(10)->get() as $o) { $result->push(['name'=>sprintf('%s (%s:%s)',$o->name,$o->supplier_name,$o->pivot_id),'value'=>'/u/home/'.$o->id,'category'=>'Suppliers']); } // Look for Account foreach (Account::Search($request->input('term')) ->whereIN('id',$account_ids) ->orderBy('company') ->limit(10)->get() as $o) { $result->push(['name'=>sprintf('%s (%s)',$o->company,$o->lid),'value'=>'/u/home/'.$o->user_id,'category'=>'Accounts']); } // Look for a Service foreach (Service::Search($request->input('term')) ->whereIN('account_id',$account_ids) ->orderBy('id') ->limit(20)->get() as $o) { $result->push(['name'=>sprintf('%s (%s) %s',$o->name,$o->lid,$o->active ? '' : 'INACT'),'value'=>'/u/service/'.$o->id,'category'=>$o->category_name]); } // Look for an Invoice foreach (Invoice::Search($request->input('term')) ->whereIN('account_id',$account_ids) ->orderBy('id') ->limit(10)->get() as $o) { $result->push(['name'=>sprintf('%s: %s',$o->lid,$o->account->name),'value'=>'/u/invoice/'.$o->id,'category'=>'Invoices']); } if (Gate::any(['wholesaler'],new Payment)) { // Look for Payments foreach (Payment::Search($request->input('term')) ->whereIN('account_id',$account_ids) ->limit(10)->get() as $o) { $result->push(['name'=>sprintf('%s: %s $%s',$o->lid,$o->account->name,number_format($o->total,2)),'value'=>'/a/payment/addedit/'.$o->id,'category'=>'Payments']); } } return $result ->sortBy(function($item) { return $item['category'].$item['name']; }) ->values(); } }