furqanDev's avatar

Update fields only specific times in a specific period.

I have an application where user can edit the fields. But I want to only let them update fields only 5 times a year.

What is the best way to do this kind of task ?

0 likes
5 replies
bugsysha's avatar

Depending on the UI. If you only want to block part of the UI, then conditionally load it. If you want to disable access to the page, then block it with middleware. You (and a bunch of others on this forum) need to explain better what you want to achieve.

So many edge cases you haven't explained. Note that the answer can only be good as the question. All other scenarios would be just guessing things from the side of the person who is answering.

furqanDev's avatar

@bugsysha I'm asking about how can I manage to keep record of the tries of the user.

I can then manage to load it conditionally or add a middleware to block the user.

Elliot_putt's avatar

Just an idea you could have a database number for the User which is like $updated_ammount = 0 ; Then in the function every time a field is edited add one to this variable. then in your middleware if auth()->user()->$updated_ammount >=5 don't allow etc....

1 like
CarlEOgden's avatar

How about storing 3 fields in your users table, dateedited, numberofedits, edtiingdisabled.

When a user logs in, check:- If editingdisabled is true and dateedited less than 12 months, don't allow editing If editingdisabled is false, allow editing

Saving an edit:- If dateedited is null or > 12 months, set dateedited to currentdate, numberofedits = 1,, editingdisabled = false if dateedited is less than 12 months and numberofedits < 5 allow editing, increment numberofedits by 1 if numberofedits = 5, editingdisabled = true

You might need to tweak this but you'll work it out! Carl.

Please or to participate in this conversation.