Getting new records from query based on values of older records
up vote
0
down vote
favorite
I have a query scope that checks which matches have to be add on to the query based on what the current time is.
Matches will be displayed if the start_date
from that match is between this Tuesday and the next Tuesday and they also need a status
field of SCHEDULED
.
A new set of matches has to be loaded when that matchday comes to an end. This can either be Sunday or Monday. now I noticed that the next matchday will start on november 24th, this means that on Tuesday november 13th, no matches will be add on to the query. Working with times will not be a useful method if I still want the upcoming matches to be displayed the day after the last match has finished.
My goal is to always add the new upcoming matches when all current matches have ended.
Code
Query
$matches = Match::thisWeekScheduled()->get();
Scope for getting correct matches based on time
public function scopeThisWeekScheduled($query) {
$start_date = now()->previous(Carbon::TUESDAY);
$end_date = now()->next(Carbon::TUESDAY);
return $query->whereDate('date','>', $start_date)->whereDate('date','<', $end_date)->where('status', 'SCHEDULED');
}
Match migration
Schema::create('matches', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->integer('match_id');
$table->string('homeTeam');
$table->string('awayTeam');
$table->string('status');
$table->dateTime('date');
$table->integer('matchday');
$table->integer('homeScore')->nullable();
$table->integer('awayScore')->nullable();
});
// last match of this matchday
// match_id = 233136
// homeTeam = Arsenal FC
// awayTeam = Wolverhampton Wanderers FC
// status = FINISHED
// date = 2018-11-11 16:30:00
// matchday = 12
// homeScore = 1
// awayScore = 1
// First upcoming match
// match_id = 233144
// homeTeam = Fulham FC
// awayTeam = Southampton FC
// status = SCHEDULED
// date = 2018-11-24 15:00:00
// matchday = 13
// homeScore = NULL
// awayScore = NULL
Extra information:
- I have every match of the season in my database. Matches have a
status ofSCHEDULED
orFINISHED
. - Im using a scheduled task that gets the updated match information from an API. Status of the match gets updated when the API has different values.
- A matchday has 10 matches
Any tips on approaching my issue?
php mysql laravel
add a comment |
up vote
0
down vote
favorite
I have a query scope that checks which matches have to be add on to the query based on what the current time is.
Matches will be displayed if the start_date
from that match is between this Tuesday and the next Tuesday and they also need a status
field of SCHEDULED
.
A new set of matches has to be loaded when that matchday comes to an end. This can either be Sunday or Monday. now I noticed that the next matchday will start on november 24th, this means that on Tuesday november 13th, no matches will be add on to the query. Working with times will not be a useful method if I still want the upcoming matches to be displayed the day after the last match has finished.
My goal is to always add the new upcoming matches when all current matches have ended.
Code
Query
$matches = Match::thisWeekScheduled()->get();
Scope for getting correct matches based on time
public function scopeThisWeekScheduled($query) {
$start_date = now()->previous(Carbon::TUESDAY);
$end_date = now()->next(Carbon::TUESDAY);
return $query->whereDate('date','>', $start_date)->whereDate('date','<', $end_date)->where('status', 'SCHEDULED');
}
Match migration
Schema::create('matches', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->integer('match_id');
$table->string('homeTeam');
$table->string('awayTeam');
$table->string('status');
$table->dateTime('date');
$table->integer('matchday');
$table->integer('homeScore')->nullable();
$table->integer('awayScore')->nullable();
});
// last match of this matchday
// match_id = 233136
// homeTeam = Arsenal FC
// awayTeam = Wolverhampton Wanderers FC
// status = FINISHED
// date = 2018-11-11 16:30:00
// matchday = 12
// homeScore = 1
// awayScore = 1
// First upcoming match
// match_id = 233144
// homeTeam = Fulham FC
// awayTeam = Southampton FC
// status = SCHEDULED
// date = 2018-11-24 15:00:00
// matchday = 13
// homeScore = NULL
// awayScore = NULL
Extra information:
- I have every match of the season in my database. Matches have a
status ofSCHEDULED
orFINISHED
. - Im using a scheduled task that gets the updated match information from an API. Status of the match gets updated when the API has different values.
- A matchday has 10 matches
Any tips on approaching my issue?
php mysql laravel
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a query scope that checks which matches have to be add on to the query based on what the current time is.
Matches will be displayed if the start_date
from that match is between this Tuesday and the next Tuesday and they also need a status
field of SCHEDULED
.
A new set of matches has to be loaded when that matchday comes to an end. This can either be Sunday or Monday. now I noticed that the next matchday will start on november 24th, this means that on Tuesday november 13th, no matches will be add on to the query. Working with times will not be a useful method if I still want the upcoming matches to be displayed the day after the last match has finished.
My goal is to always add the new upcoming matches when all current matches have ended.
Code
Query
$matches = Match::thisWeekScheduled()->get();
Scope for getting correct matches based on time
public function scopeThisWeekScheduled($query) {
$start_date = now()->previous(Carbon::TUESDAY);
$end_date = now()->next(Carbon::TUESDAY);
return $query->whereDate('date','>', $start_date)->whereDate('date','<', $end_date)->where('status', 'SCHEDULED');
}
Match migration
Schema::create('matches', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->integer('match_id');
$table->string('homeTeam');
$table->string('awayTeam');
$table->string('status');
$table->dateTime('date');
$table->integer('matchday');
$table->integer('homeScore')->nullable();
$table->integer('awayScore')->nullable();
});
// last match of this matchday
// match_id = 233136
// homeTeam = Arsenal FC
// awayTeam = Wolverhampton Wanderers FC
// status = FINISHED
// date = 2018-11-11 16:30:00
// matchday = 12
// homeScore = 1
// awayScore = 1
// First upcoming match
// match_id = 233144
// homeTeam = Fulham FC
// awayTeam = Southampton FC
// status = SCHEDULED
// date = 2018-11-24 15:00:00
// matchday = 13
// homeScore = NULL
// awayScore = NULL
Extra information:
- I have every match of the season in my database. Matches have a
status ofSCHEDULED
orFINISHED
. - Im using a scheduled task that gets the updated match information from an API. Status of the match gets updated when the API has different values.
- A matchday has 10 matches
Any tips on approaching my issue?
php mysql laravel
I have a query scope that checks which matches have to be add on to the query based on what the current time is.
Matches will be displayed if the start_date
from that match is between this Tuesday and the next Tuesday and they also need a status
field of SCHEDULED
.
A new set of matches has to be loaded when that matchday comes to an end. This can either be Sunday or Monday. now I noticed that the next matchday will start on november 24th, this means that on Tuesday november 13th, no matches will be add on to the query. Working with times will not be a useful method if I still want the upcoming matches to be displayed the day after the last match has finished.
My goal is to always add the new upcoming matches when all current matches have ended.
Code
Query
$matches = Match::thisWeekScheduled()->get();
Scope for getting correct matches based on time
public function scopeThisWeekScheduled($query) {
$start_date = now()->previous(Carbon::TUESDAY);
$end_date = now()->next(Carbon::TUESDAY);
return $query->whereDate('date','>', $start_date)->whereDate('date','<', $end_date)->where('status', 'SCHEDULED');
}
Match migration
Schema::create('matches', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->integer('match_id');
$table->string('homeTeam');
$table->string('awayTeam');
$table->string('status');
$table->dateTime('date');
$table->integer('matchday');
$table->integer('homeScore')->nullable();
$table->integer('awayScore')->nullable();
});
// last match of this matchday
// match_id = 233136
// homeTeam = Arsenal FC
// awayTeam = Wolverhampton Wanderers FC
// status = FINISHED
// date = 2018-11-11 16:30:00
// matchday = 12
// homeScore = 1
// awayScore = 1
// First upcoming match
// match_id = 233144
// homeTeam = Fulham FC
// awayTeam = Southampton FC
// status = SCHEDULED
// date = 2018-11-24 15:00:00
// matchday = 13
// homeScore = NULL
// awayScore = NULL
Extra information:
- I have every match of the season in my database. Matches have a
status ofSCHEDULED
orFINISHED
. - Im using a scheduled task that gets the updated match information from an API. Status of the match gets updated when the API has different values.
- A matchday has 10 matches
Any tips on approaching my issue?
php mysql laravel
php mysql laravel
asked Nov 12 at 2:13
Dax
1168
1168
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
$matches = Match::where('created_at', '>=', Carbon::now()->subDays(14)->toDateTimeString());
here You can use subDays() has value as you want to show previous days ..i use for 14 days
This is not what i'm trying to achieve, This will basically load all my matches at once
– Dax
Nov 12 at 11:26
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
$matches = Match::where('created_at', '>=', Carbon::now()->subDays(14)->toDateTimeString());
here You can use subDays() has value as you want to show previous days ..i use for 14 days
This is not what i'm trying to achieve, This will basically load all my matches at once
– Dax
Nov 12 at 11:26
add a comment |
up vote
0
down vote
$matches = Match::where('created_at', '>=', Carbon::now()->subDays(14)->toDateTimeString());
here You can use subDays() has value as you want to show previous days ..i use for 14 days
This is not what i'm trying to achieve, This will basically load all my matches at once
– Dax
Nov 12 at 11:26
add a comment |
up vote
0
down vote
up vote
0
down vote
$matches = Match::where('created_at', '>=', Carbon::now()->subDays(14)->toDateTimeString());
here You can use subDays() has value as you want to show previous days ..i use for 14 days
$matches = Match::where('created_at', '>=', Carbon::now()->subDays(14)->toDateTimeString());
here You can use subDays() has value as you want to show previous days ..i use for 14 days
edited Nov 12 at 5:22
answered Nov 12 at 5:11
raushan kumar
6910
6910
This is not what i'm trying to achieve, This will basically load all my matches at once
– Dax
Nov 12 at 11:26
add a comment |
This is not what i'm trying to achieve, This will basically load all my matches at once
– Dax
Nov 12 at 11:26
This is not what i'm trying to achieve, This will basically load all my matches at once
– Dax
Nov 12 at 11:26
This is not what i'm trying to achieve, This will basically load all my matches at once
– Dax
Nov 12 at 11:26
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255201%2fgetting-new-records-from-query-based-on-values-of-older-records%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown