Struggling with an "active" filter and scope on a resource

I have an account resource. The database table has a inactive_flag column that is a Y or N value.

I want my account resource table to be only active accounts by default, and the ability to include inactive with a filter. I also want my global search to only search active accounts, and the view page of the account to not care whether it's active or inactive.

At first I implemented a global scope to scope active only by default. This works great for the table listing and global search. I can use a filter to include inactive by removing the global scope on the base query. However, my problem occurs when I want to navigate to the view page of the account, then the global scope applies again and I get a 404. I'm not sure how I can remove the global scope on the view page of the account?

Alternatively I tried without global scopes and modifying the initial query of the table to include ->where('inactive_flag', '!=', 'Y') which works, but then my filter doesn't work to include inactive because if I use either the query or baseQuery methods, it still results in a query that does this: where inactive_flag != 'Y' and inactive_flag = 'Y' which obviously no accounts will match.

How do I solve this?
Was this page helpful?