dipcb05's avatar

How to check who have visited my specific pages

I want to check those users, who have visited a single page. if i modify anything of that page, i want to mail or notify those users, who has visited my page.

so how i can check this?

0 likes
8 replies
Snapey's avatar

Are these users logged in (and identifiable) ?

ismaile's avatar

Assuming the users are authenticated, you can have a dedicated table for pages with:

  • id
  • name

And a dedicated pivot table page_user to store visits:

  • id
  • page_id
  • user_id

The pages table would be filled upfront.

Now for the pivot table, you should think of how to store visits. If you do it in every controller associated to every route, you would be repeating yourself a lot. So, that's where a middleware can be handy. In the middleware code, you can store visits for each authenticated user. If you need to keep track of only one visit per user, you need to make sure you don't store a visit twice.

Then, it would be pretty easy to get the visitors for a page, if you have a visitors belongsToMany relationship defined, you can do something like:

$page = App\Page::where('name', 'aRandomPageName')->first();
foreach($page->visitors as $visitor) {
    // send the email / notify
}
1 like
automica's avatar

@pistle in this case, the users have to be logged in. So we can assume that contact has been made in the past.

dipcb05's avatar

@pistle actually i want to mail them about any modification of information. that's why i need to know. and i know them, because there is a admin panel who's controlling it, they have a database of them. they have to create account

Please or to participate in this conversation.