2016-09-01 6 views
0

これはおそらく非常に簡単な質問です。しかし、私は立ち往生しています。これは私がテーブルの最後コントローラの文字列の値をlaravelのビューに渡して出力する

public function totalBillc3() 
    { 
     $total = Collection::where('collector_id', '=', 3)->sum('package'); 

     return View::make('users.collector3', compact('total',$total)); 



    } 

そして私は私が持っている

   <tr> 
       <td colspan="4" class="noborders"></td> 
       <th class="text-right" scope="row">TOTAL</th> 
       <td class="text-right">{{ $total}}</td> 
      </tr> 

を書かれているビュー内で印刷するビューの列の合計を渡すためにtryngています私のコントローラ機能です私のルート完全に設定が、エラーが

Undefined variable: total (View: /Volumes/G/zipbillingsoft.com/resources/views/users/collector3.blade.php). Please help. 

答えて

1

compact()を示しているが、その後、それらの文字列のように名前の変数を探し、引数として一個の以上の文字列を取ります。

言い換えれば、あなたは

compact('total', $total) 

ではなく、単に

compact('total') 

を行うべきではありませんそして、あなたは複数の変数を持っている場合は、行う

compact('total', 'something', 'something_else') 

ドキュメント:http://php.net/compact

+0

表示方法は? –

+0

'{{$ total}}'とまったく同じです。 –

0

あなたはView :: make in functionでcompactを間違えた。次のコードを試してください:

return View::make('users.collector3', compact('total',['total'])); 
+0

私の見方で印刷するには? –

関連する問題