title: Where should I be saving a model in Laravel MVC?
body: <p>I'm trying to get a more concrete understanding of MVC and keeping the controller layer as thin as possible. </p>
  
  <p>One thing I keep asking myself is "Where should I call modelname->save()?"</p>
  
  <p>Looking at the Laravel documentation, they set data to the model and call save in the controller which doesn't seem right...</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use App\Flight;
  use Illuminate\Http\Request;
  use App\Http\Controllers\Controller;
  
  class FlightController extends Controller
  {
      public function store(Request $request)
      {
          // Validate the request...
  
          $flight = new Flight;
  
          $flight-&gt;name = $request-&gt;name;
  
          $flight-&gt;save();
      }
  }
  </code></pre>
  
  <p>This is quite a simple example and might be why they do it all in the controller.</p>
  
  <p>From my understanding and everything I've been reading, all business logic should sit inside the model, the controller is responsible for "traffic control" between the view and the model. </p>
  
  <p>So would I be calling save inside the model itself? or should I be using a service layer?</p>
  
  <hr>
  
  <p>Here is my current problem with example data.</p>
  
  <p>I am updating the status of a model. The row already exists in the DB. I use PATCH /route/ to get to the controller method. From there I get the model.</p>
  
  <pre><code>class TimecardController extends Controller {
  ...
      public function markAsPass(Request $request, $id) {
          $test = Test::findOrFail($id);
  
          //I don't think this is the corect way  
          //$test-&gt;status = "passed";
          //$test-&gt;markedBy = "Teacher123";
          //$test-&gt;save();
  
  
          $test-&gt;passed();
          ...
          return redirect($redirect_url);
      }
  }
  
  class Test extends Model {
  ...
      public function passed() {
          $this-&gt;status = "passed";
  
          //would I call save here? 
          //$this-&gt;save();
      }
  }
  </code></pre>
  
  <p>Do I take an approach like above? Or do I create a service layer where I would use the model instance to call the model functions and then call save on the model?</p>
  
  <pre><code>//in service class
  public function makeTestAsPassed($test){
      $test-&gt;passed();
      $test-&gt;save();
  
  }
  </code></pre>
  
  <p>Please let me know if any claification is needed.</p>