title: Total, Quantity, Price in Laravel
body: <p>I have a table named 'products' with 5 fields (id, title, price, quantity, total).</p>
  
  <p>My goal is to calculate via the form products.create the total, price * quantity.</p>
  
  <p><strong>Database - products</strong></p>
  
  <pre><code>public function up()
      {
          Schema::create('products', function (Blueprint $table) {
              $table-&gt;bigIncrements('id');
              $table-&gt;string('title');
              $table-&gt;integer('quantity');
              $table-&gt;double('price');
              $table-&gt;double('total')-&gt;nullable();
              $table-&gt;timestamps();
          });
      }
  </code></pre>
  
  <p><strong>Model - product</strong></p>
  
  <pre><code>protected  $fillable = ['title', 'quantity', 'price', 'total']; 
  
      public function setTotalAttribute()
      {
          $this-&gt;total = $this-&gt;quantity * $this-&gt;price; 
      }
  
      public function getTotalAttribute($value)
      {
          return $value;
      }
  </code></pre>
  
  <p>** Controller - ProductController**</p>
  
  <pre><code>public function index()
      {
          $products = Product::oldest()-&gt;paginate(5);
          return view('admin.products.index', compact('products'))
                    -&gt;with('i', (request()-&gt;input('page', 1)-1)*5);
      }
  
  
      public function create()
      {
  
          $products = Product::all();
          return view('admin.products.create', compact('products'));
      }
  
  
      public function store(Request $request)
      {
          $request-&gt;validate([
                  'title' =&gt; 'required',
                  'quantity' =&gt; 'required',
                  'price' =&gt; 'required',
                  'total' =&gt; 'required'
  
  
          ]);
  
          Product::create($request-&gt;all());
  
          return redirect()-&gt;route('products.index')
                      -&gt;with('success', 'save');
      }
  </code></pre>
  
  <p>My problem is in my view "products.create" I have 3 fields when I encode the 3 fields, nothing happens ???</p>
  
  <p><strong>Products.create</strong></p>
  
  <pre><code>&lt;form class="panel-body" action="{{route('products.store')}}" method="POST" novalidate&gt;
                @csrf
                &lt;fieldset class="form-group {{ $errors-&gt;has('title') ? 'has-error' : '' }}"&gt;
                  &lt;label for="form-group-input-1"&gt;Title&lt;/label&gt;
                  &lt;input type="text" name="title" id="title" class="form-control" value="{{ old('title')}}"/&gt;
                  {!! $errors-&gt;first('title', '&lt;span class="help-block"&gt;:message&lt;/span&gt;') !!}
                &lt;/fieldset&gt;
  
                &lt;fieldset class="form-group {{ $errors-&gt;has('quantity') ? 'has-error' : '' }}"&gt;
                  &lt;label for="form-group-input-1"&gt;Quantity&lt;/label&gt;
                  &lt;input type="text" name="quantity" id="quantity" class="form-control" value="{{ old('quantity')}}"/&gt;
                  {!! $errors-&gt;first('quantity', '&lt;span class="help-block"&gt;:message&lt;/span&gt;') !!}
                &lt;/fieldset&gt;
  
                &lt;fieldset class="form-group {{ $errors-&gt;has('price') ? 'has-error' : '' }}"&gt;
                  &lt;label for="form-group-input-1"&gt;Price&lt;/label&gt;
                  &lt;input type="text" name="price" id="price" class="form-control" value="{{ old('price')}}"/&gt;
                  {!! $errors-&gt;first('price', '&lt;span class="help-block"&gt;:message&lt;/span&gt;') !!}
                &lt;/fieldset&gt;
  
                &lt;a href="{{route('products.index')}}" class="btn btn-primary pull-right"&gt;Back&lt;/a&gt;
                &lt;button type="submit" class="btn btn-sm btn-primary"&gt;Valider&lt;/button&gt;
  </code></pre>
  
  <p>Thank you for help.</p>