A
A
arseniylebedev2018-08-10 17:19:40
Laravel
arseniylebedev, 2018-08-10 17:19:40

Is there a method on the model that is called when the model is loaded?

I need to increment the number of views when the data in the model is loaded.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2018-08-10
@arseniylebedev

To increment something, there is a ->increment('field') method.
If you do it when the model is loaded, how many views you will have, simply because somewhere the selection is made for various internal needs.
At the same time, there is no protection against cheating, etc.
The views increment should be added exactly where the result is displayed and seasoned with checks for the fact that the person / ip address has already looked and all that, if necessary.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question