title: About designing a course system. When should I inspect assignments due or not? Where should I put this logic?
body: <p>I am working on designing a system for students, teachers, etc. to use, and I'm using <strong>Laravel Framework</strong> to develop. Teachers can create course and assign homework to the courses' students, and they can <strong>set the due date for them separately</strong>.</p>
  
  <p>My question is:</p>
  
  <ol>
  <li><strong>When should I check the date is expired or not</strong>?</li>
  <li><strong>Where should I put this logic?</strong></li>
  </ol>
  
  <p>In my opinion:</p>
  
  <ol>
  <li>For example, we have course Mathematics for student Aaron, and the teacher is Josh.
  When Aaron or Josh <strong>log into</strong> the system, check their course Mathematics is expired or not. Otherwise, only check when they click on the assignment or course page.</li>
  <li><p>Create a middleware for checking, and apply it to Route.</p>
  
  <pre><code>Route::group(['middleware' =&gt; 'check'], function(){
      Route::get('/dashboard'); 
      Route::get('/courses');
      Route::get('/assignments');
  }
  </code></pre>
  
  <p>Otherwise, create a service(use service and repository design pattern) for controller to call.</p>
  
  <pre><code>//controller 
  public function getDashboard(){
      $user = Auth::user();
      ...
      $this-&gt;assignmentService-&gt;check(); //check for assignment
      $this-&gt;courseService-&gt;check(); // check for course
      ...
  }
  </code></pre></li>
  </ol>