2017-02-25 70 views
-1
$price = DB::table('price') 
     ->where([ 
     ['days_id', $days AND 'deals_id', $selected_deal] ]) 
     ->pluck('price'); 

我使用此代碼來獲得單一價格,但它給我所有的價格,這些條件來了。如何從laravel中的表中檢索單個字段5.2

記錄在數據庫: enter image description here

+0

當我從你的問題,你應該只是總結了那些懂了吧? –

+0

沒有先生,我只想要一個價格不多 –

+0

解析代碼後,您的代碼將返回'price'表中找到的每個實例的'price'。 –

回答

0

正如你可以閱讀here

摘去方法檢索所有的值對於給定的關鍵

我不知道你到底想做什麼,但你應該看看first,lastfilter方法。如果覺得最後一個會是最適合你的。

+0

這兩個過濾器都很重要。我想只有一個領域這些都mathes –

+0

$價格= DB ::表('價格') - >其中(['days_id','2'和'deals_id','4']]) - >拔毛( '價格'); Illuminate \ Support \ Collection對象([items:protected] => Array([0] => 40 [1] => 60 [2] => 80 [3] => 100) 這是給我的這些結果 [4] => 120 [5] => 140)) –

1

使用value()方法,你可以得到一個價值/場從表中你想

$price = DB::table('price') 
     ->where([ 
     ['days_id', $days AND 'deals_id', $selected_deal] ]) 
     ->value('price'); 
相關問題