What is CI4 BaseModel usage patterns?

Answer

Creating a custom BaseModel in CI4 that all your models extend is a powerful pattern for sharing common behaviour. Create app/Models/BaseModel.php extending CodeIgniter\Model. Add common functionality: soft deletes enabled by default (protected $useSoftDeletes = true), timestamps enabled (protected $useTimestamps = true), common validation patterns (reusable rule sets), shared callbacks (e.g., always trim string fields before insert), common scopes (active(), orderByLatest()), and audit fields (automatically set created_by from the logged-in user ID in a beforeInsert callback). Add helper methods: findOrFail($id) throws 404 instead of returning null, paginator($perPage) returns paginated results with consistent defaults. All application models extend BaseModel instead of CI4's Model. This reduces repetition across models and ensures consistent behaviour like soft deletes and audit trails without having to remember to configure them in each model.