首页 > 解决方案 > 无法使用 ->where()->get() 从 DB 获取行;

问题描述

我在数据库中有一个名为 invoices 的表格,以及带有值的 automonth 和 autoyear 列。我不知道为什么这个函数返回空数组。我想获取具有 automonth 值和 autoyear 值的行。请帮我。

$autoyear = date('Y');
$automonth = date('m');

$autonumber = DB::table("invoices as invoices")
    ->where('automonth', '=', '$automonth')
    ->where('autoyear', '=', '$autoyear') 
    ->get();

标签: phpmysqldatabaselaraveleloquent

解决方案


您以错误的方式传递变量:

$autonumber = DB::table("invoices as invoices")
    ->where('automonth', '=', $automonth)
    ->where('autoyear', '=', $autoyear) 
    ->get();

传递变量名时不需要 '' ...


推荐阅读