I am using Laravel Framework 6.16.0.
I want to select data via sql functions, such as CONCAT('Q', QUARTER(transaction_date)).
However, I get an error:
Column not found: 1054 Unknown column 'CONCAT('Q', QUARTER(transaction_date))' in 'field list'
The query looks like the following:
$days = 365 * 2; // two years
$trx = DB::connection('mysql_prod')->table('product')->select(array("transaction_date", "CONCAT('Q', QUARTER(transaction_date))", "YEAR(transaction_date)", "trx_type", "amount_range", "transaction_value", "symbol"))
->leftJoin('companies', 'product.companies_id', '=', 'companies.id')
->leftJoin('persons', 'persons.id', '=', 'product.persons_id')
->where('companies.symbol', '=', $s->symbol)
->where('persons.person_type', '=', 'manager')
->whereDate('transaction_date', '>=', Carbon::now()->subDays($days))
->orderBy('transaction_date', 'desc')
->get();
Any suggestion how to use SQL-functions within an eloquent select statement?
Appreciate your reply!
DB::rawfor the CONCAT stuff as it thinks you are trying to select 'columns' withselect