I have the following code in multiple files. I would like to DRY it up.
The purpose of the code is to return the value of the current week which can be 1 to 17.
model Schedule.php
public function scopeCurrentWeekGames($query) {
return $query->where('week', '=', $this->currentWeek());
}
public function currentWeek()
{
$currentWeek = Schedule::distinct()
->where('gameTime', '<', Carbon::now()->addHours(50))
->orderBy('gameTime', 'desc')
->lists('week')
->first();
return $currentWeek;
}
model Pick.php
public function scopeCurrentWeekPicks($query) {
$currentWeek = Schedule::distinct()
->where('gameTime', '<', Carbon::now()->addHours(50))
->orderBy('gameTime', 'desc')
->lists('week')
->first();
return $query->where('week', '=', $currentWeek);
}
controller PicksController.php
$currentWeek = Schedule::distinct()
->where('gameTime', '<', Carbon::now()->addHours(50))
->orderBy('gameTime', 'desc')
->lists('week')
->first();
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire