Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

For a really fast resolution I would go with a ProfileView model, and directly place it into the ProfilesController@show (or whatever controller you're using)

ProfileView::firstOrCreate(['user_id' => Auth::user()->id, 'profile_id' => $profile_id]);

Or if you would like to know how many times he visited a profile, and when was the last visit:

$profile_view = ProfileView::firstOrNew(['user_id' => Auth::user()->id, 'profile_id' => $profile_id]);
$profile_view->count++;
$profile_view->save();

So you can get the users (with proper relationships) $profile->views, and the last visit for each is the updated_at (if you're using timestamps)

for example:

Users who visited this profile:
<ul>
@foreach($profile->views as $view)
  <li>{{ $view->user->name }} ({{ $view->count }} times)</li>
@endforeach
</ul>

It maybe a bit weird, but I hope that helped.

Last updated 9 years ago.
0

Hi, I didn't really understand what to do in my ProfileView model.

Thank you.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

ranslobo ranslobo Joined 11 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.