diff --git a/app/Support/Spotlight.php b/app/Support/Spotlight.php index 134476d..a4e335c 100644 --- a/app/Support/Spotlight.php +++ b/app/Support/Spotlight.php @@ -2,6 +2,7 @@ namespace App\Support; +use App\Models\Holding; use App\Models\Portfolio; use Illuminate\Http\Request; @@ -10,20 +11,35 @@ class Spotlight public function search(Request $request) { + $results = collect(); + if (!$request->user()) { - return collect(); + + return $results; } - $portfolios = Portfolio::where('title', 'LIKE', '%'.$request->input('search').'%')->limit(5)->get(); + $portfolios = Portfolio::myPortfolios()->where('title', 'LIKE', '%'.$request->input('search').'%')->limit(5)->get(); + $portfolios->each(function($portfolio) use ($results) { - return $portfolios->map(function($portfolio){ - - return [ - 'name' => $portfolio->title, + $results->push([ + 'name' => 'Portfolio: '. $portfolio->title, 'description' => null, 'link' => route('portfolio.show', ['portfolio' => $portfolio->id]), 'avatar' => null - ]; + ]); }); + + $holdings = Holding::myHoldings()->where('symbol', 'LIKE', '%'.$request->input('search').'%')->limit(5)->get(); + $holdings->each(function($holding) use ($results) { + + $results->push([ + 'name' => 'Holding: '. $holding->symbol, + 'description' => $holding->portfolio->title, + 'link' => route('portfolio.show', ['portfolio' => $holding->portfolio->id]), + 'avatar' => null + ]); + }); + + return $results; } } \ No newline at end of file