title: Laravel: Getting the Value of a Field In a Table
body: <p>What I'm trying to do is get the available credits from the users table and 'credits' field and get the price of the current item in the foreach loop which is the 'normalprice' field in the 'items' table. </p>
  
  <p>When a user fills in the amount he wants to put toward the 'normalprice' of an item, i want to subtract from the number in his 'credits' field, and create a new variable for 'This is the price of the item after you've put credits toward it' and display it. </p>
  
  <p>The users table and items table are on a many-to-many relationship, and i've been able to display a user item by doing</p>
  
  <pre><code>$user-&gt;item
  </code></pre>
  
  <p>What i've done is bellow is wrong, because 'normalprice' in '$item->normalprice;' is not a property. I'm trying to find out how I can make $itemprice equal the value of 'normalprice' in the current @foreach ($user->items as $item)</p>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>    public function allocateCredit(){
      $validator = Validator::make(Input::all(),
      array(
          'puttoward' =&gt;  'Integer',
      ));
      $user = Auth::user();
      $items  = Item::all();
      $userItems = Auth::user()-&gt;items;
      $itemprice = $item-&gt;normalprice;
      $available = $user-&gt;credits;
      $goodtogo = ($available &gt; $itemprice) ? TRUE : FALSE;
      if($goodtogo === true){
          $howmuch = Input::get('puttoward');
          $newavailable =  $howmuch - $available;
          $itembalance = $itemprice - $howmuch;
          $user-&gt;credits = $newavailable;
      }
      if($user-&gt;save()){
          return Redirect::route('account')-&gt;with('global', 'Success.');
      }
  }    
  </code></pre>
  
  <p><strong>View:</strong></p>
  
  <pre><code>            @foreach ($user-&gt;items as $item)
          &lt;div class="sep"&gt;
              &lt;div class="nameIt"&gt;
                  {{ $item-&gt;name }}
                  &lt;form action="{{ URL::route('allocate-credits-post') }}" method="post" role="form"&gt;
                      &lt;div class="form-group"&gt;
                      &lt;label for="exampleInputPassword1"&gt;Allocate credits&lt;/label&gt;
                      &lt;input type="intiger" class="form-control" name="puttoward" placeholder="$0.00"&gt;
                      &lt;/div&gt;
                      &lt;button type="submit" class="btn btn-default"&gt;Submit&lt;/button&gt;
                      {{ Form::token() }}
                  &lt;/form&gt;
  </code></pre>