I'm using OctoberCMS with Laravel 5. I have several models and they need to be joined.
I have 'PaymentData' model and 'AppsData' model. They both have 'mem_id' column and I want to get the 'app_process' column's values from 'AppsData' model based on the 'PaymentData' model's data.
What I tried below causes this error message.
"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
PaymentData model
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 model
class AppsData extends Model
{
use \October\Rain\Database\Traits\Validation;
public $table = 'BYAPPS_apps_data';
public $rules = [
];
}
what I tried in 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();
}
What did I wrong here? Please, someone help me...!_!
You can try with writing a custom query like this:
$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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.