Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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 如何将我的SQL转换为Laravel Builder_Php_Mysql_Laravel - Fatal编程技术网

Php 如何将我的SQL转换为Laravel Builder

Php 如何将我的SQL转换为Laravel Builder,php,mysql,laravel,Php,Mysql,Laravel,我建议您使用雄辩而非查询生成器 它很容易使用,而且很有说服力。我建议您阅读有关的所有文档 假设您有一个模型登录尝试。你只需要这样做: SELECT count(ip) AS failed_attempts FROM login_attempts WHERE ip = $ip AND date < (NOW - INTERVAL 24 HOUR) 或者,如果愿意,可以使用查询生成器: // Eloquent $failedAttempts = LoginAttempt::where('

我建议您使用雄辩而非查询生成器

它很容易使用,而且很有说服力。我建议您阅读有关的所有文档

假设您有一个模型登录尝试。你只需要这样做:

SELECT count(ip) AS failed_attempts
FROM login_attempts
WHERE ip = $ip
  AND date < (NOW - INTERVAL 24 HOUR)
或者,如果愿意,可以使用查询生成器:

// Eloquent
$failedAttempts = LoginAttempt::where('ip', $ip)
    ->where('date', '<', now()->subHours(24))->count();
// Query builder
$failedAttempts = \DB::table('login_attempts')->where('ip', $ip)
    ->where('date', '<', now()->subHours(24))->count();