Hello @exshapoval
You can do it with a raw statement.
This can be with $query->addSelect(DB::raw("IF(domainExpired IS NULL, '3000-01-01', domainExpired) as d2"));
or with $query->selectRaw("IF(domainExpired IS NULL, '3000-01-01', domainExpired) as d2");
See: https://laravel.com/docs/10.x/queries#selectraw
Ps. I didn't test the example so it could have a small mistake :)
To fix the issue with the backticks being added to the IF statement in your select query, you can use the DB::raw() method in Laravel.
The DB::raw() method allows you to include raw SQL expressions in your query without Laravel adding backticks or escaping the SQL code. Here's how you can use it in your indexQuery function: $resourceTable = 'projects';
$query->select("{$resourceTable}.*"); $query->addSelect(DB::raw("IF(domainExpired IS NULL, '3000-01-01', domainExpired) as d2")); By using DB::raw() method to wrap the IF statement, Laravel will treat it as a raw SQL expression and won't add any backticks to it.
This should solve the issue with the backticks being added to your IF statement in the select query.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community