2013-11-21 29 views
0
$table = 'favorite_contents'; 
$contents = DB::table($table) 
     ->join('contents', function($join) use($table){ 
      $join->on("$table.content_id", '=', 'contents.id'); 
     }) 
     ->whereIn("$table.content_id",$ids) 
     ->update(array(
       "$table.expired" => 1, 
       "$table.type" => "contents.type" 
     )); 

"$table.expired" => 1工作正常,但"$table.type" => "contents.type"没有。更新table1字段中的表2字段值加入laravel流利

所以这个问题与在内容表中获取类型的值有关,如何在不诉诸foreach的情况下做到这一点?

回答

0

"$table.type" => "contents.type"更改为"$table.type" => DB::raw("contents.type")。如你所知,我相信update()方法试图保存字符串“contents.type”而不是从“contents”中获取“type”列。如果您使用的是MySQL,并且favorite_contents.type是数字列,则可能会将“contents.type”转换为0而不显示错误。