feat: add holdings to search
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Support;
|
namespace App\Support;
|
||||||
|
|
||||||
|
use App\Models\Holding;
|
||||||
use App\Models\Portfolio;
|
use App\Models\Portfolio;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
@@ -10,20 +11,35 @@ class Spotlight
|
|||||||
public function search(Request $request)
|
public function search(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
$results = collect();
|
||||||
|
|
||||||
if (!$request->user()) {
|
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){
|
$results->push([
|
||||||
|
'name' => 'Portfolio: '. $portfolio->title,
|
||||||
return [
|
|
||||||
'name' => $portfolio->title,
|
|
||||||
'description' => null,
|
'description' => null,
|
||||||
'link' => route('portfolio.show', ['portfolio' => $portfolio->id]),
|
'link' => route('portfolio.show', ['portfolio' => $portfolio->id]),
|
||||||
'avatar' => null
|
'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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user