2017-07-21 37 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。“购买你的照片:”;

希望对你有帮助!