我正在将 OctoberCMS 与 Laravel 5 结合使用。 我有几个模型,需要将它们连接起来。
我有“PaymentData”模型和“AppsData”模型。它们都有“mem_id”列,我想根据“PaymentData”模型的数据从“AppsData”模型中获取“app_process”列的值。
我在下面尝试的操作会导致此错误消息。
"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'app_process' in 'where clause' (SQL: select count(*) as aggregate from
BYAPPS_apps_payment_data
wherepay_type
!= 1 andamount
= 0 andapp_process
!= 8)" on line 664 of /home/ljw/public_html/byapps_cms/vendor/laravel/framework/src/Illuminate/Database/Connection.php
支付数据模型
class PaymentData extends Model
{
use \October\Rain\Database\Traits\Validation;
public $table = 'BYAPPS_apps_payment_data';
public $rules = [
];
public $hasOne = [
'joins' => [
'Jiwon\Byapps\Models\AppsData',
'key' => 'mem_id',
'otherKey' => 'mem_id'
]
];
}
AppsData 模型
class AppsData extends Model
{
use \October\Rain\Database\Traits\Validation;
public $table = 'BYAPPS_apps_data';
public $rules = [
];
}
我在 home.htm 中尝试过的内容
use Jiwon\Byapps\Models\AppsData;
use Jiwon\Byapps\Models\PaymentData;
function onGetAppChartData()
{
$this['appsFree'] = PaymentData::where('pay_type', '!=', '1')
->where('amount', '=', '0')
->where('app_process', '!=', '8')
->count();
}
我在这里做错了什么?请有人帮助我...!_!
最佳答案
您可以尝试编写如下自定义查询:
$this['appsFree'] = \DB::table('BYAPPS_apps_payment_data as p')
->join('BYAPPS_apps_data as a', 'a.mem_id', '=', 'p.mem_id')
->where('p.pay_type', '!=', '1')
->where('p.amount', '=', '0')
->where('p.app_process', '!=', '8')
->count();
关于php - 如何在 OctoberCMS 的连接表中使用 where 子句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57565574/