Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dev786's avatar

How can i count the post views and save to DB

Hi, I want to count the posts view and save to DB.

And i need and Advanced search for my Laravel app, i have three differents camps in my DB table , "name, category and price", how can i create and searchbox for these three options.

I am new in Laravel so i don't have enough informaction about laravel.

Please any one help me to solve this problem.

0 likes
2 replies
Snapey's avatar

You have two problems. Thats two questions.

Basically you have to work at it and not just come here expecting people to write code for you.

If you want to count access, how do you think it could be done? Maybe when you load the post, you increment a count and then save it?

Sergiu17's avatar
Sergiu17
Best Answer
Level 60

For counting views of posts, you could use Redis. This is one simple example.

// show post method
public function show(Post $post)
{
    Redis::incr('post:' . $post->id . ':count');

    return view('posts.index', compact('post'));
}

Read more here about Redis with Laravel https://laravel.com/docs/5.6/redis

For advanced search, there are tons of information about searching and filtering in Laravel.

Please or to participate in this conversation.