I can not access to $ad->stats->todayImpressions(); in my detail view of an ads. How can access to a filter relationship? When I try to dump this:
dd($ad->stats->todayImpressions());
I get this error:
Method todayImpressions does not exist.
These are the two model involved:
class Ad extends Model
{
/**
* The stats that belong to the ads.
*/
public function stats(){
return $this->hasMany('App\Models\Stats', 'ad', 'id');
}
}
class Stats extends Model
{
/**
* The # of the today impressions for the current stats.
*/
public function scopeTodayImpressions($query) {
$todayTime = strtotime('today midnight');
return $query->where('thetime', $todayTime);
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire