2016-05-14 97 views
0

我正在查詢作爲if語句的一部分的行數。如何使用口才能查詢Laravel 5.2中的行數?

我用的代碼如下:

$company = DB::table('customers')->where('business', 'Auth::user()->name')->value('business'); 
@if (count($company==0) 

<div class="alert alert-danger" role="alert"> 
<strong>Please click here to register full company details</strong> 

@endif 

UPDATE

{{$countCompany = App\customers::where('business', Auth::user()->name)->count()}} 
@if ($countCompany==0) 
<div class="alert alert-danger" role="alert"> 
<strong>Please click here to register full company details</strong> 
@endif 

謝謝

回答

0

我已成功地做了變通方法

<?php 
$user = Auth::user()->name; 
$company = DB::table('customers')->where('business', $user)->value('business'); 

?> 

@if (is_null($company)) 

<div class="alert alert-danger" role="alert"> 
<strong>Please click here to register full company details</strong> 
</div> 
@endif 

作品爲我所需要的。

0

使用->count()方法

$count = $company->count(); 

你也有此錯誤,遺漏)

@if (count($company==0)) 
+0

謝謝@Rishi我已更新使用您的技術我正在「調用一個非對象的成員函數count()」 我試圖在部分內部的消息中執行此操作(如果有幫助的話)。 –

+0

@JamesParsons:你的問題解決了嗎? – C2486

0

嘗試用雄辯

$countCompany = App\Customer::where('business', Auth::user()->name)->count(); 
+0

感謝您的回覆@Abderrahim Soubai Elidrissi,我更新了上面的代碼。我收到了「嘗試獲取非對象屬性」的回覆。我試圖在刀片內的部分消息中執行此操作(如果有幫助的話)。 –

+0

歡迎Bro,請確保客戶是您的客戶表的模型名稱。並嘗試從顯示中分派查詢,以便在您的Controller中查詢並通過使用 - > With()將數據傳遞給您的視圖。 –