Welcome Guest, Not a member yet? Register   Sign In
restrict query in callback
#1

(This post was last modified: 09-12-2023, 06:40 AM by sjender.)

Hi,

I want to do some checks prior to some queries in the model.
In the $beforeUpdate and $beforeDelete callback I append the query by 
PHP Code:
$this->builder()->where('id'null); 
when the conditions are not met. (my ID's won't ever be NULL, resulting in an UPDATE or DELETE which won't work)

But this won't work on an insert.

I have a callback which determines whether the insert is valid, but I can't find a way to prevent the insert from happening when the right conditions are not met.
I have tried $this->builder()->resetQuery, but that still doesn't prevent the query from running...
Reply
#2

You can try Conditional Statements.
Reply
#3

I've looked into that....

But how would I fit that into a callback function in the Model?
I don't want to use the WHEN method on every insert query, I would like to centralize it in the model
Reply
#4

Why don't you throw an exception when the conditions are not met?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB