Getting new records from query based on values of older records










0














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 of SCHEDULED or FINISHED.

  • 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?










share|improve this question


























    0














    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 of SCHEDULED or FINISHED.

    • 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?










    share|improve this question
























      0












      0








      0







      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 of SCHEDULED or FINISHED.

      • 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?










      share|improve this question













      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 of SCHEDULED or FINISHED.

      • 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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 12 '18 at 2:13









      Dax

      1478




      1478






















          1 Answer
          1






          active

          oldest

          votes


















          0














          $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






          share|improve this answer






















          • This is not what i'm trying to achieve, This will basically load all my matches at once
            – Dax
            Nov 12 '18 at 11:26











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          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

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          $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






          share|improve this answer






















          • This is not what i'm trying to achieve, This will basically load all my matches at once
            – Dax
            Nov 12 '18 at 11:26
















          0














          $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






          share|improve this answer






















          • This is not what i'm trying to achieve, This will basically load all my matches at once
            – Dax
            Nov 12 '18 at 11:26














          0












          0








          0






          $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






          share|improve this answer














          $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







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 12 '18 at 5:22

























          answered Nov 12 '18 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 '18 at 11:26

















          • This is not what i'm trying to achieve, This will basically load all my matches at once
            – Dax
            Nov 12 '18 at 11:26
















          This is not what i'm trying to achieve, This will basically load all my matches at once
          – Dax
          Nov 12 '18 at 11:26





          This is not what i'm trying to achieve, This will basically load all my matches at once
          – Dax
          Nov 12 '18 at 11:26


















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Use pre created SQLite database for Android project in kotlin

          Darth Vader #20

          Ondo