Laravel:数组到字符串转换

时间:2017-07-21 04:15:18

标签: laravel

SettingController.php

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 ";
  }
}
  

SettingController.php第373行中的ErrorException:数组到字符串   转化

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

2 个答案:

答案 0 :(得分: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 ";
} 

答案 1 :(得分:0)

$email变量有多个记录。如果您使用$email作为users表中的电子邮件地址,则可以按照以下代码进行操作:

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

$ content = $ email。“购买你的照片:”;

希望对你有所帮助!!!