Wel basically you can do it yourself via the database, just add a colomn to your `users` table with `last_activity`, than update the last activity with NOW() each time someone refresh. To check who's online just run a query based on 5 minutes or so like where NOW() - 5minutes < last activity
Yes, but that will result in a lot of database requests, which is a Footgun for bigger scale projects. I think his Idea in the video with the cache is way cleaner. But I could be wrong about the scalability of the cache in larger contexts
So for me it wasnt precise enough because what about the idle state? Imagine not quitting and not doing any requests. Like being afk or something. That state doesn't exist so I would be offline. I havn't wrote anything yet, but I would do it like in the video and in addition check if the user has either quit (window.onbeforeunload) or logged of. However, thanks for your inspiration. Helped me to understand how to approach that task for a personal project
Thank you for this tutorial, i think its the best solution so far, but i have a question not sure if you could help? unfortunately i have deferent implementation on my app, My recent online users list are available on all dashboard pages (it requiers a view composer) with a button to show full list of on line users. So how would you approach this issue. 1- Get recent 10 Logged in users 2- Make the list available thought all pages 3- Redirect user to full list of online users when they click on the (view all button)
after watching your tutorial i tried to implement same code to my application but it didn't work because i have slightly different implementation than the one you have presented in the tutorial above. My Whos online list is not in a seperate route? instead its avaliable on all dashboard pages ??? its a sliding menu on the right side of the screen?? (so i think i need a view composer for that not seperate routed page). Unfortunitly i was not able to load cached files to the view composer neither passing datat to all pages of my dashboard. so my question is -> HOW CAN WE IMPLEMENT YOUR SOLUTION to list whos online To All dashboard pages, so the basicaly an admin user will be able to check this list from anywhere on dashboard after his authinicated. I hope my question is clear this time. Great channel, ... i watch all your videos
Show the list of users in the table ( first name, last name, position and the status.) This should be loaded from user table. For the status, you have to fetch the recent status from the second table called status. Provide option to change the user active status ( Online, Away, Do not disturb ) . The other users logged in should see the status changing in the list ( no need of web socket ) we can just refresh the page to see the updated results. We need login with validation. List with filters and sorting. Option to add new user ( No need any option to edit or delete ). Main the active status history in a new table ( At what time they changed the status ). The current status should be fetched from this table.
Well done but the major problem is that you have to refresh the page to update the status. I'm looking for a way to update the user's status without refreshing the page and I think there is no other way than Ajax.
This is the general problem with server rendered views such as blade templates. Without using a websocket you would mostly require some form of javascript: AJAX, or Inertia with Vue/React/Svelte or other methods to subscribe to data
I only get the logged in user for each browser window where I have logged in as different users. I see others had the same problem, tried changing CACHE_DRIVER to "file" instead of "array" as someone suggested, this didn't work. I followed each and every step of the tutorial. Any clue?
Try setting the cache to "database" and create the following schema: Schema::create('cache', function ($table) { $table->string('key')->unique(); $table->text('value'); $table->integer('expiration'); }); A database will be more performant than a file.
Hi Bro, I exactly did the same thing like you in laravel 5.4 application. But It's showing me an error Call to undefined method stdClass::isOnline(). What can I do now, please suggest me. It's very kind for me.
Hey dear. Do you have stdClass file or Class or Model in your application ? I mean, did you write the isOnline function in that class? If you did the same thing, you should't have any problem now. You might have done something differently.
Yes dear I wrote isOnline function in my User.php model. But when I apply if($user->isOnline()) condition in user view like you to detect the online status of my user its show me this kind of error.
@@eliasali7070 Try this in your UsersController. Retrieves all users, and passes instance of User model so $user->isOnline() is defined. /** * Displays online status of each user * * @return View */ public function onlineStatus(User $user) { $users = User::get();
Call to undefined method Illuminate\View\Engines\CompilerEngine::isOnline() , I followed the video step by step and yet it has been giving this error. Would you like to put the code of this tutorial in guthub?
Try this in your UsersController. Retrieves all users, and passes instance of User model so $user->isOnline() is defined. /** * Displays online status of each user * * @return View with instance of User model */ public function onlineStatus(User $user) { $users = User::get();
Maybe the best way for you would be to write a script and stick to it (not a code script, a presentation script :D). That way you will avoid making it longer than needed. Look at Jeff at laracasts. He doesn't say one word more than needed :) and he is the best tutor there is!
Try this in your UsersController. Retrieves all users, and passes instance of User model so $user->isOnline() is defined. /** * Displays online status of each user * * @return View with instance of User model */ public function onlineStatus(User $user) { $users = User::get();
/** * Log the user out of the application. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function logout(Request $request) { Cache::forget('user-is-online-' . Auth::user()->id); // forget cache key when user logs out $this->guard()->logout(); $request->session()->invalidate(); return $this->loggedOut($request) ?: redirect('/'); } I guess we need to add this code in case the user log out by clicking the logout button to remove the key that contains the user->id from the Cache
Wel basically you can do it yourself via the database, just add a colomn to your `users` table with `last_activity`, than update the last activity with NOW() each time someone refresh. To check who's online just run a query based on 5 minutes or so like where NOW() - 5minutes < last activity
please can you send the code for that
I never though that a youtube comment would help me more than stackoverflow, but here you are proving me wrong. Thanks
Technically yes u can of course do that but u can do it if u make task schedular
Yes, but that will result in a lot of database requests, which is a Footgun for bigger scale projects. I think his Idea in the video with the cache is way cleaner. But I could be wrong about the scalability of the cache in larger contexts
Excellent job bro..thank you so much..
Well done bro, very well!
nice bro.. this is helpful. Thanks
You're welcome 🙌
Very Helpful Tutorial. Thank you, Sir.
Thanks for nice sharing
OMG, that's brilliant!
Awesome, pretty simple and useful!
thanks bro for this tutorial and for your awesome channel
So for me it wasnt precise enough because what about the idle state? Imagine not quitting and not doing any requests. Like being afk or something. That state doesn't exist so I would be offline.
I havn't wrote anything yet, but I would do it like in the video and in addition check if the user has either quit (window.onbeforeunload) or logged of. However, thanks for your inspiration. Helped me to understand how to approach that task for a personal project
What is considered an activity? Would the user moving mouse or scrolling be considered an activity?
It's navigating between links in the website
you are awesome bundle of Thanks!
great job bro..thank you so much..
Very important this Thanx!!!
Very welcome :)
Thank you for this tutorial, i think its the best solution so far, but i have a question not sure if you could help? unfortunately i have deferent implementation on my app, My recent online users list are available on all dashboard pages (it requiers a view composer) with a button to show full list of on line users.
So how would you approach this issue.
1- Get recent 10 Logged in users
2- Make the list available thought all pages
3- Redirect user to full list of online users when they click on the (view all button)
Sorry, what is your exact question ? I didn't get your question ? :)
after watching your tutorial i tried to implement same code to my application but it didn't work because i have slightly different implementation than the one you have presented in the tutorial above.
My Whos online list is not in a seperate route? instead its avaliable on all dashboard pages ??? its a sliding menu on the right side of the screen?? (so i think i need a view composer for that not seperate routed page).
Unfortunitly i was not able to load cached files to the view composer neither passing datat to all pages of my dashboard.
so my question is -> HOW CAN WE IMPLEMENT YOUR SOLUTION to list whos online To All dashboard pages, so the basicaly an admin user will be able to check this list from anywhere on dashboard after his authinicated.
I hope my question is clear this time.
Great channel, ... i watch all your videos
Nice vid, its working
so hlpfl ty broh
Show the list of users in the table ( first name, last name, position and the status.) This should be loaded from user table. For the status, you have to fetch the recent status from the second table called status.
Provide option to change the user active status ( Online, Away, Do not disturb ) . The other users logged in should see the status changing in the list ( no need of web socket ) we can just refresh the page to see the updated results.
We need login with validation.
List with filters and sorting. Option to add new user ( No need any option to edit or delete ).
Main the active status history in a new table ( At what time they changed the status ). The current status should be fetched from this table.
How can i get last online time to display instead of `offline` ? for example: Last seen today at 4:30PM . Something like this?
you can user "diffForHumans". Look like this ...
{{ auth()->user()->current_sign_in_at->diffForHumans() }}
Awesome
create playlists for your videos. difficult to to follow ur videos as it is now. Algorythm keeps suggesting other videos as follow up
Thanks for your suggestion. I will do it :)
love the work...these are very useful
Well done but the major problem is that you have to refresh the page to update the status. I'm looking for a way to update the user's status without refreshing the page and I think there is no other way than Ajax.
This is the general problem with server rendered views such as blade templates. Without using a websocket you would mostly require some form of javascript: AJAX, or Inertia with Vue/React/Svelte or other methods to subscribe to data
I only get the logged in user for each browser window where I have logged in as different users.
I see others had the same problem, tried changing CACHE_DRIVER to "file" instead of "array" as someone suggested, this didn't work.
I followed each and every step of the tutorial.
Any clue?
have no Idea. it worked just fine for me :(
Try setting the cache to "database" and create the following schema:
Schema::create('cache', function ($table) {
$table->string('key')->unique();
$table->text('value');
$table->integer('expiration');
});
A database will be more performant than a file.
Oh, I found in the docs the next command to generate the schema automatically
php artisan cache:table
cheers!
superb thanks
Hi Sir, what should i put in controller? when i login in multiple user only display one online..
Hi, Do you use different browsers ?
i used incognito... by the way, what should i put in my controller $user = User::all()?
do you have email? i ask you something... thanks.
Yeah. Drop your email here. I will email you back. :)
batangkritiko703@gmail.com i follow your tutz but it doesn't work to me... hope you help me.
Hi Bro,
I exactly did the same thing like you in laravel 5.4 application. But It's showing me an error Call to undefined method stdClass::isOnline(). What can I do now, please suggest me. It's very kind for me.
Hey dear. Do you have stdClass file or Class or Model in your application ? I mean, did you write the isOnline function in that class?
If you did the same thing, you should't have any problem now. You might have done something differently.
Yes dear I wrote isOnline function in my User.php model. But when I apply if($user->isOnline()) condition in user view like you to detect the online status of my user its show me this kind of error.
@@eliasali7070 Try this in your UsersController. Retrieves all users, and passes instance of User model so $user->isOnline() is defined.
/**
* Displays online status of each user
*
* @return View
*/
public function onlineStatus(User $user)
{
$users = User::get();
return view('users.online-status', compact('users'));
}
amigo una pregunta si alamaceno en la carpeta stroage de laravel puedo aceder a ella sin hacerla publica
Sorry, I don't understand your language :(
Can you help. I only want to see online users
Hello brother may you help me by sending code in zip file ?
Am only getting the current user logged in all the different browsers..the others are offline
You might have missed something. Did you follow all the steps ?
Found the solution. The problem was in my .env. The cache_driver was set to array instead of file. .Thank you for this Video
very welcome :)
Laravel 8 working..?
Call to undefined method Illuminate\View\Engines\CompilerEngine::isOnline() ,
I followed the video step by step and yet it has been giving this error. Would you like to put the code of this tutorial in guthub?
sorry dear, I already deleted the project. You can check out the article here
erikbelusic.com/tracking-if-a-user-is-online-in-laravel/
Try this in your UsersController. Retrieves all users, and passes instance of User model so $user->isOnline() is defined.
/**
* Displays online status of each user
*
* @return View
with instance of User model
*/
public function onlineStatus(User $user)
{
$users = User::get();
return view('users.online-status', compact('users'));
}
but this is not real-time if you want to check the user is online or offline you have to refresh the page
Auth::check() everytime false in middleware, what’s wrong?
I added my middleware in web group
I don’t know how it works in your case cuz auth session did not call in this load order
its work in laravel 5.4?
Yeah, it works.
can you do a tutorial on how to consume Rest Api using laravel
What's that BTW? You mean restful APIs ?
getting and posting data from laravel to a web api using libraries like guzzle
if(Auth::check()) it is not going in this condition as well. I have followed all the steps.
@Sfwan Essam thanks. It worked.
What if user don’t refresh the page?
Not working for me. What about cofigure config/cache.php?
what's not working buddy. Do you get error ?
@@CodeInspire I understand what my problem is. I really did not configure cache to save to the database.
@@gigavaxer6557 awesome. thanks for mentioning. it will help others. :)
@@CodeInspire Thanks I hope it'll help other too)
@@gigavaxer6557 mined isn't working how do I configure it pls
What about away status?
I need that without page refresh without use ajax set time out is that possible?
No need to reload the page, the way to solve . tks
Useful stuff but you could have explained this in 3 minutes easily.
I try my best to make shorter videos, it I must explain and make it clear. don't know why it takes too long every time :D
Maybe the best way for you would be to write a script and stick to it (not a code script, a presentation script :D). That way you will avoid making it longer than needed. Look at Jeff at laracasts. He doesn't say one word more than needed :) and he is the best tutor there is!
Sure, he is my favorite tutor too :) . But, he has a lots of experience, I will try your way next time.
@codeinspire u r good n down to earth teacher
cool thx
very welcome :)
How to try
Call to undefined method stdClass::isOnline() i have error of this i follow the tutorial but this is happen
Did you write your isOnline() function . Please re-watch the video, you might have missed something.
thanks ialready fix becasue in my controller i got missing code thats why it does not view the right way thankks a lot for this video
Bro ano nilagay mo sa controller mo sa index? $users = Auth::user()? or $users = User::all(); ?
@@ermetanyoPh $users = User::get();
Try this in your UsersController. Retrieves all users, and passes instance of User model so $user->isOnline() is defined.
/**
* Displays online status of each user
*
* @return View
with instance of User model
*/
public function onlineStatus(User $user)
{
$users = User::get();
return view('users.online-status', compact('users'));
}
/**
* Log the user out of the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function logout(Request $request)
{
Cache::forget('user-is-online-' . Auth::user()->id); // forget cache key when user logs out
$this->guard()->logout();
$request->session()->invalidate();
return $this->loggedOut($request) ?: redirect('/');
}
I guess we need to add this code in case the user log out by clicking the logout button to remove the key that contains the user->id from the Cache
ty
is it realtime
I don't think so. Since he was reloading the page to see the status. I'm trying his method but with react and pusher to make it realtime
code please
please upload source code on github