title: What is the correct Laravel-way to define a method (public function) inside a model and execute the function inside a controller?
body: <p>I have a method to calculate the price of a specific product. I wrote some code <strong>that is working</strong>, but I have a feeling that it's not "the correct way" of doing it. Am I doing this wrong or is there a better way? This is what I got:</p>
  
  <p>The ProductsController:</p>
  
  <pre><code>$amount = 10;
  $product = Product::where('type', $type)-&gt;firstOrFail();
  dd($product-&gt;getPrice($amount, $product['id']));
  </code></pre>
  
  <p>The Product (model):</p>
  
  <pre><code>namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Product extends Model
  {
      public function getPrice($amount, $product_id) {
  
      $product = Product::where('id', $product_id)-&gt;firstOrFail();
      $product_price = $product['price'] * $amount;
      return $product_price;
  
      }
  
  }
  </code></pre>
  
  <p>I will have much more complicated calculations inside the getPrice method in the future. I want to be able to get a products price on the checkout page with this method. The exact product price needs some complicated calculations and is not stored by itself inside the database.</p>