I am using laravel framework to develop web application ,i am using soft-deletes so while fetching the data from database i have to check weather the column is null or not ,for that i wrote a following query
QueryBuilder
$today= "2022-09-23 00:00:00";
$this->repository->pushCriteria(new WhereCriteria('date_of_leaving', $today));
querylog
array (
'query' => 'select * from `employees` where `date_of_leaving` = ? and `employees`.`deleted_at` is null',
'bindings' =>
array (
0 => '2022-09-23 00:00:00',
),
'time' => 2.36,
),
table structure
+-----------------+-----------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-----------------+------+-----+---------+----------------+
| id | bigint unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | | NULL | |
| email | varchar(255) | NO | | NULL | |
| joining_date | timestamp | NO | | NULL | |
| manager_id | bigint unsigned | NO | MUL | NULL | |
| image_path | varchar(255) | YES | | NULL | |
| date_of_leaving | timestamp | YES | | NULL | |
| still_working | timestamp | YES | | NULL | |
| deleted_at | timestamp | YES | | NULL | |
+-----------------+-----------------+------+-----+---------+----------------+
data
+---------------------+---------------------+
| date_of_leaving | deleted_at |
+---------------------+---------------------+
| 2022-09-23 00:00:00 | 2022-09-23 11:47:11 |
| 2022-09-23 00:00:00 | 2022-09-23 12:36:46 |
| 2022-09-23 00:00:00 | 2022-09-23 13:09:55 |
| NULL | NULL |
| 2022-09-06 00:00:00 | NULL |
| NULL | NULL |
| NULL | NULL |
| NULL | NULL |
| NULL | 2022-09-23 11:45:01 |
| NULL | NULL |
| NULL | NULL |
+---------------------+---------------------+
Actually in database three matching records are there with the above condition but this query is not fetching the data ,i was suspecting deteled_at was considering NULL as string
2
Answers
Try This.
array (
‘query’ => ‘select * from
employees
wheredate_of_leaving
Is Null andemployees
.deleted_at
is null’,‘bindings’ =>
array (
0 => ‘2022-09-23 00:00:00’,
),
‘time’ => 2.36,
),
Try doing this, i believe the package you are using does not support Laravel’s softDelete() feature.