I have a table object Users in a CakePHP 3.6 application that has a beforeFind callback like so:
public function beforeFind(Event $event, Query $query, $options = []) {
$query->where(['Users.active']);
return $query;
}
As you can see above, the intention here is to fetch only active users for all find queries. The problem I have is that for newly registered users (which are not active until they confirm their registration), the find query on the users table will not work because it will not return inactive users.
When people validate their registration I send them a code in the url. I would like to verify the request to see if the code parameter exists then I won't have to check only for active users like so:
public function beforeFind(Event $event, Query $query, $options = []) {
if(code parameter does not exist) {
$query->where(['Users.active']);
}
return $query;
}
But I don't know how to get the request parameter inside beforeFind in my UsersTable object.
Any help please?