Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 5.2使用雄辩的方法获取每行数据的日期差异_Php_Mysql_Eloquent_Laravel 5.2 - Fatal编程技术网

Php Laravel 5.2使用雄辩的方法获取每行数据的日期差异

Php Laravel 5.2使用雄辩的方法获取每行数据的日期差异,php,mysql,eloquent,laravel-5.2,Php,Mysql,Eloquent,Laravel 5.2,我希望在查询数据库的每一行以计算天数时,获取与date today的日期差,并将其设置为引用。如何以生动的方式构建它?谢谢 $query ="SELECT unix_timestamp(NOW()) - unix_timestamp(created_at) AS time_diff from users WHERE trial=1"; $result=mysql_query($query) or die(mysql_error()); while($row=mysql_fetch_assoc(

我希望在查询数据库的每一行以计算天数时,获取与date today的日期差,并将其设置为引用。如何以生动的方式构建它?谢谢

$query ="SELECT unix_timestamp(NOW()) - unix_timestamp(created_at) AS time_diff from users WHERE trial=1";
$result=mysql_query($query) or die(mysql_error());

while($row=mysql_fetch_assoc($result)) 
{ 
 $diff= $row['time_diff']
}
您可以在中使用selectRaw

或者你想用

DB::table('users')
->selectRaw('unix_timestamp(NOW()) - unix_timestamp(created_at) AS time_diff')
->where('trial',1)
->get();
Model::select(DB::raw('unix_timestamp(NOW()) - unix_timestamp(created_at) AS time_diff'))
->where('trial',1)
->get();