app/Models/User.php
//user can only be hero for one time in the same week
user can only be hero for one time in the same week
user can only be hero for one time in the same week
public function hero()
    {
        $weekStartEnd = currentWeekStartEndDate();
        $startWeek = date('Y-m-d', strtotime($weekStartEnd['startWeek']));
        $endWeek = date('Y-m-d', strtotime($weekStartEnd['endWeek']));
        return $this->hasOne('App\Models\Hero', 'user_id', 'id')
            ;
    }
public function hero ( ) { $ weekStartEnd = currentWeekStartEndDate ( ) ; $ startWeek = date ( 'Y-m-d' , strtotime ( $ weekStartEnd [ 'startWeek' ] ) ) ; $ endWeek = date ( 'Y-m-d' , strtotime ( $ weekStartEnd [ 'endWeek' ] ) ) ; return $ this -> hasOne ( 'App\Models\Hero' , 'user_id' , 'id' ) ; }
user can only be hero for one time in the same week
user can only be hero for one time in the same week
/*->where(function ($q) use ($startWeek, $endWeek) {
                $q->whereBetween('created_at', [$startWeek, $endWeek])
                    ->orWhereDate('created_at', '=', $startWeek)
                    ->orWhereDate('created_at', '=', $endWeek);
            })*/