0

I have an articles site based on Laravel and Vue, I want to count the number of visits for each article (when the user opens the article the number of visits increases by one), in Laravel I used the eloquent-viewable package, but with Laravel + Vue I don't know how to do it.

can you help me please

1 Answer 1

1

you can try this approach

in your mount event register this function

mounted() {
        
        this.view();
    },
methods: {
        view() {
            axios.get('/home/food_view/' + this.$route.params.id).then((response) => {
                if (response.data.error)
                    Toast.fire({
                        icon: 'error',
                        title: response.data.error,
                    })
            });
        },
    }

and in your migration create a column

$table->integer('view')->default(0); 

and then in your controller do something like that

$model = Model::find($id);
$model->view += 1;
$model->save();

update you can use these route in route.js

{
                path: '/food_details/:id/:slug',
                name: 'food_details',
                component: foodDetails
            },
Sign up to request clarification or add additional context in comments.

1 Comment

Can you write how the Route should be in the API file please?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.