Support the ongoing development of Laravel.io →
posted 1 year ago
Nova
0
moderator

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 :)

0

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.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Dev exshapoval Joined 2 Mar 2023

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.