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.
Hi, I didn't really understand what to do in my ProfileView model.
Thank you.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community