2017-07-21 36 views
0

SettingController.phpLaravel:數組字符串轉換

public function SendPicture(Request $request) { 

    $title = "Picture Purchase"; 

    $domain = $_SERVER['SERVER_NAME']; 

    $email = DB::table('users') - > where('domain', $domain) - > get(); 

    $content = "$email purchase your picture : "; 

    foreach($request - > input('pic') as $key => $value) { 
    $content. = "$value".".jpg "; 
    } 
} 

ErrorException在SettingController.php行373:數組字符串轉換

line 373: $content = "$email purchase your picture : "; 
+1

有'$ email'可能是收藏集,所以你不能像上面那樣轉換成字符串 –

+0

在你SendPicture函數dd($ email)之後請顯示那個輸出 –

+2

試試$ email = DB :: table('users ') - > where('domain',$ domain) - > value('email'); –

回答

0

如果你只是完成一個記錄你可以使用value方法獲取直接字符串:

$email = DB::table('users')->where('domain', $domain)->value('email'); 

    $content = $email ." purchase your picture : "; 

注:有一個在你的每個循環中的邏輯錯誤也從$value刪除「」:

foreach($request->input('pic') as $key => $value) { 
    $content. = $value.".jpg "; 
} 
0

$email變量有一個以上的記錄。如果您使用$email電子郵件地址從users表,那麼你可以按照下面的代碼:

$電子郵件= DB ::表( '用戶') - >在哪裏( '域',$域) - >第一();

$ content = $ email。「購買你的照片:」;

希望對你有幫助!