wip
This commit is contained in:
@@ -3,13 +3,14 @@
|
||||
namespace App\Interfaces\MarketData;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Scheb\YahooFinanceApi\ApiClient;
|
||||
use Scheb\YahooFinanceApi\ApiClientFactory as YahooFinance;
|
||||
|
||||
class YahooMarketData implements MarketDataInterface
|
||||
{
|
||||
public function __construct(
|
||||
public $client
|
||||
) {
|
||||
public ApiClient $client;
|
||||
|
||||
public function __construct() {
|
||||
|
||||
// create yahoo finance client factory
|
||||
$this->client = YahooFinance::createApiClient();
|
||||
|
||||
@@ -28,6 +28,18 @@ class MarketData extends Model
|
||||
'dividend_yield'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'last_dividend_date' => 'datetime',
|
||||
'market_value' => 'float',
|
||||
'fifty_two_week_high' => 'float',
|
||||
'fifty_two_week_low' => 'float',
|
||||
'forward_pe' => 'float',
|
||||
'trailing_pe' => 'float',
|
||||
'market_cap' => 'float',
|
||||
'book_value' => 'float',
|
||||
'dividend_yield' => 'float'
|
||||
];
|
||||
|
||||
public function holdings()
|
||||
{
|
||||
return $this->hasMany(Holding::class, 'symbol', 'symbol');
|
||||
|
||||
@@ -18,7 +18,10 @@ class Spotlight
|
||||
return $results;
|
||||
}
|
||||
|
||||
$portfolios = $request->user()->portfolios()->where('title', 'LIKE', '%'.$request->input('search').'%')->limit(5)->get();
|
||||
$portfolios = $request->user()->portfolios()
|
||||
->where('title', 'LIKE', '%'.$request->input('search').'%')
|
||||
->limit(5)
|
||||
->get();
|
||||
$portfolios->each(function($portfolio) use ($results) {
|
||||
|
||||
$results->push([
|
||||
@@ -29,13 +32,20 @@ class Spotlight
|
||||
]);
|
||||
});
|
||||
|
||||
$holdings = $request->user()->holdings()->where('holdings.symbol', 'LIKE', '%'.$request->input('search').'%')->limit(5)->get();
|
||||
$holdings = $request->user()->holdings()
|
||||
->where('holdings.quantity', '>', 0)
|
||||
->where(function ($query) use ($request) {
|
||||
return $query->where('holdings.symbol', 'LIKE', '%'.$request->input('search').'%')
|
||||
->orWhere('market_data.name', 'LIKE', '%'.$request->input('search').'%');
|
||||
})
|
||||
->limit(5)
|
||||
->get();
|
||||
$holdings->each(function($holding) use ($results) {
|
||||
|
||||
$results->push([
|
||||
'name' => 'Holding: '. $holding->symbol,
|
||||
'name' => 'Holding: '.$holding->market_data->name.' ('.$holding->symbol.')',
|
||||
'description' => $holding->portfolio->title,
|
||||
'link' => route('portfolio.show', ['portfolio' => $holding->portfolio->id]),
|
||||
'link' => route('holding.show', ['portfolio' => $holding->portfolio->id, 'symbol' => $holding->symbol]),
|
||||
'avatar' => null
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user