2019-06-21 06:21:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
2019-06-29 00:14:12 +00:00
|
|
|
use App\Models\{Account,Service\Adsl};
|
2019-06-21 06:21:48 +00:00
|
|
|
|
|
|
|
class SearchController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Show the application dashboard.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function search(Request $request)
|
|
|
|
{
|
|
|
|
if (! $request->input('term'))
|
|
|
|
return [];
|
|
|
|
|
|
|
|
$result = collect();
|
|
|
|
$uo = Auth::user();
|
|
|
|
|
|
|
|
# Look for Account
|
|
|
|
foreach (Account::Search($request->input('term'))
|
2019-06-29 00:14:12 +00:00
|
|
|
->whereIN('id',$uo->all_accounts()->pluck('id'))
|
2019-06-21 06:21:48 +00:00
|
|
|
->orderBy('company')
|
|
|
|
->orderBy('last_name')
|
|
|
|
->orderBy('first_name')
|
|
|
|
->limit(10)->get() as $o)
|
|
|
|
{
|
|
|
|
$result->push(['label'=>sprintf('A:%s %s',$o->aid,$o->name),'value'=>'/u/account/'.$o->id]);
|
|
|
|
}
|
|
|
|
|
2019-06-29 00:14:12 +00:00
|
|
|
# Look for an ADSL/NBN Service
|
|
|
|
foreach (Adsl::Search($request->input('term'))
|
|
|
|
->whereIN('account_id',$uo->all_accounts()->pluck('id'))
|
|
|
|
->orderBy('service_number')
|
|
|
|
->limit(10)->get() as $o)
|
|
|
|
{
|
|
|
|
$result->push(['label'=>sprintf('S:%s (%s)',$o->name,$o->service->sid),'value'=>'/u/service/'.$o->id]);
|
|
|
|
}
|
|
|
|
|
2019-06-21 06:21:48 +00:00
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|