To add a default query condition to a model in October CMS, you can use the ‘boot()’ method in your model to apply a global scope. To do this follow the steps given below:
Find the model you want to apply the default query condition to, typically located in
/models
.
Add a ‘boot()’ method in the model to apply the condition:
Test the Condition: Query the model to ensure the default condition status = 'active' is applied automatically:
If you need to query without this condition, use ‘withoutGlobalScope’: