How to Detect User Online Status In Laravel 5.6 - The Simplest way

Поделиться
HTML-код
  • Опубликовано: 25 окт 2024

Комментарии • 107

  • @KimYoungUn69
    @KimYoungUn69 6 лет назад +8

    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

    • @ibrahimyaradua9212
      @ibrahimyaradua9212 6 лет назад

      please can you send the code for that

    • @ArianiHaliti
      @ArianiHaliti 5 лет назад +1

      I never though that a youtube comment would help me more than stackoverflow, but here you are proving me wrong. Thanks

    • @abdalrhmanhussin2541
      @abdalrhmanhussin2541 3 года назад

      Technically yes u can of course do that but u can do it if u make task schedular

    • @djent_prog_core_guitarcovers
      @djent_prog_core_guitarcovers Год назад

      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

  • @VipulPatel-mw4jj
    @VipulPatel-mw4jj 3 года назад

    Excellent job bro..thank you so much..

  • @iamanderson
    @iamanderson 5 лет назад +4

    Well done bro, very well!

  • @hugoirwanto9905
    @hugoirwanto9905 3 года назад

    nice bro.. this is helpful. Thanks

  • @SaifulIslam-dn3tj
    @SaifulIslam-dn3tj 4 года назад

    Very Helpful Tutorial. Thank you, Sir.

  •  5 лет назад

    Thanks for nice sharing

  • @deastortion
    @deastortion 3 года назад

    OMG, that's brilliant!

  • @adnanbabakan3863
    @adnanbabakan3863 4 года назад

    Awesome, pretty simple and useful!

  • @tahashokri77
    @tahashokri77 5 лет назад

    thanks bro for this tutorial and for your awesome channel

  • @suben7226
    @suben7226 4 года назад

    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

  • @alex-rodriguez
    @alex-rodriguez 4 года назад

    What is considered an activity? Would the user moving mouse or scrolling be considered an activity?

    • @CodeInspire
      @CodeInspire  4 года назад

      It's navigating between links in the website

  • @tayyabhanif5133
    @tayyabhanif5133 4 года назад

    you are awesome bundle of Thanks!

  • @mohaimenkhalid3844
    @mohaimenkhalid3844 5 лет назад

    great job bro..thank you so much..

  • @samuelluswata
    @samuelluswata 6 лет назад +1

    Very important this Thanx!!!

  • @najmeddinhaidar9641
    @najmeddinhaidar9641 6 лет назад

    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)

    • @CodeInspire
      @CodeInspire  6 лет назад

      Sorry, what is your exact question ? I didn't get your question ? :)

    • @najmeddinhaidar9641
      @najmeddinhaidar9641 6 лет назад

      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

  • @basicg8127
    @basicg8127 5 лет назад

    Nice vid, its working

  • @SiCA-gg
    @SiCA-gg 3 года назад

    so hlpfl ty broh

  • @maddushanmukharao148
    @maddushanmukharao148 Год назад

    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.

  • @rakeshkohali8523
    @rakeshkohali8523 5 лет назад

    How can i get last online time to display instead of `offline` ? for example: Last seen today at 4:30PM . Something like this?

    • @newdaymoney1280
      @newdaymoney1280 5 лет назад

      you can user "diffForHumans". Look like this ...
      {{ auth()->user()->current_sign_in_at->diffForHumans() }}

  • @sumonchandrashil8406
    @sumonchandrashil8406 4 года назад

    Awesome

  • @PeterSserwangaShow
    @PeterSserwangaShow 6 лет назад +2

    create playlists for your videos. difficult to to follow ur videos as it is now. Algorythm keeps suggesting other videos as follow up

  • @david0705
    @david0705 3 года назад

    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.

    • @djent_prog_core_guitarcovers
      @djent_prog_core_guitarcovers Год назад

      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

  • @jonaspalsson4720
    @jonaspalsson4720 6 лет назад

    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?

    • @CodeInspire
      @CodeInspire  6 лет назад

      have no Idea. it worked just fine for me :(

    • @iamanderson
      @iamanderson 5 лет назад

      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.

    • @iamanderson
      @iamanderson 5 лет назад

      Oh, I found in the docs the next command to generate the schema automatically
      php artisan cache:table
      cheers!

  • @testraindrops5490
    @testraindrops5490 5 лет назад

    superb thanks

  • @ermetanyoPh
    @ermetanyoPh 6 лет назад

    Hi Sir, what should i put in controller? when i login in multiple user only display one online..

    • @CodeInspire
      @CodeInspire  6 лет назад

      Hi, Do you use different browsers ?

    • @ermetanyoPh
      @ermetanyoPh 6 лет назад

      i used incognito... by the way, what should i put in my controller $user = User::all()?

    • @ermetanyoPh
      @ermetanyoPh 6 лет назад

      do you have email? i ask you something... thanks.

    • @CodeInspire
      @CodeInspire  6 лет назад

      Yeah. Drop your email here. I will email you back. :)

    • @ermetanyoPh
      @ermetanyoPh 6 лет назад

      batangkritiko703@gmail.com i follow your tutz but it doesn't work to me... hope you help me.

  • @eliasali7070
    @eliasali7070 6 лет назад

    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.

    • @CodeInspire
      @CodeInspire  6 лет назад

      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.

    • @eliasali7070
      @eliasali7070 6 лет назад +1

      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.

    • @jimburns7549
      @jimburns7549 3 года назад

      @@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'));
      }

  • @xkiller838
    @xkiller838 6 лет назад

    amigo una pregunta si alamaceno en la carpeta stroage de laravel puedo aceder a ella sin hacerla publica

    • @CodeInspire
      @CodeInspire  6 лет назад

      Sorry, I don't understand your language :(

  • @donaldmjbart-williams3144
    @donaldmjbart-williams3144 2 года назад

    Can you help. I only want to see online users

  • @ojuluomod5601
    @ojuluomod5601 5 лет назад

    Hello brother may you help me by sending code in zip file ?

  • @edudev2975
    @edudev2975 6 лет назад

    Am only getting the current user logged in all the different browsers..the others are offline

    • @CodeInspire
      @CodeInspire  6 лет назад

      You might have missed something. Did you follow all the steps ?

    • @edudev2975
      @edudev2975 6 лет назад

      Found the solution. The problem was in my .env. The cache_driver was set to array instead of file. .Thank you for this Video

    • @CodeInspire
      @CodeInspire  6 лет назад +1

      very welcome :)

  • @internetcafe7203
    @internetcafe7203 3 года назад

    Laravel 8 working..?

  • @anderson7segundos
    @anderson7segundos 6 лет назад

    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?

    • @CodeInspire
      @CodeInspire  6 лет назад

      sorry dear, I already deleted the project. You can check out the article here
      erikbelusic.com/tracking-if-a-user-is-online-in-laravel/

    • @jimburns7549
      @jimburns7549 3 года назад

      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'));
      }

  • @umair-ali
    @umair-ali 3 года назад

    but this is not real-time if you want to check the user is online or offline you have to refresh the page

  • @Andrey007007PC
    @Andrey007007PC 4 года назад

    Auth::check() everytime false in middleware, what’s wrong?

    • @Andrey007007PC
      @Andrey007007PC 4 года назад

      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

  • @janerosemartinez3247
    @janerosemartinez3247 6 лет назад

    its work in laravel 5.4?

  • @yassinemsiah5052
    @yassinemsiah5052 6 лет назад

    can you do a tutorial on how to consume Rest Api using laravel

    • @CodeInspire
      @CodeInspire  6 лет назад

      What's that BTW? You mean restful APIs ?

    • @yassinemsiah5052
      @yassinemsiah5052 6 лет назад

      getting and posting data from laravel to a web api using libraries like guzzle

  • @HassaanUrRahman
    @HassaanUrRahman 4 года назад

    if(Auth::check()) it is not going in this condition as well. I have followed all the steps.

  • @thantzinhtay9525
    @thantzinhtay9525 3 года назад

    What if user don’t refresh the page?

  • @gigavaxer6557
    @gigavaxer6557 6 лет назад

    Not working for me. What about cofigure config/cache.php?

    • @CodeInspire
      @CodeInspire  6 лет назад

      what's not working buddy. Do you get error ?

    • @gigavaxer6557
      @gigavaxer6557 6 лет назад

      @@CodeInspire I understand what my problem is. I really did not configure cache to save to the database.

    • @CodeInspire
      @CodeInspire  6 лет назад

      @@gigavaxer6557 awesome. thanks for mentioning. it will help others. :)

    • @gigavaxer6557
      @gigavaxer6557 6 лет назад

      @@CodeInspire Thanks I hope it'll help other too)

    • @feranmiafrica9528
      @feranmiafrica9528 4 года назад

      @@gigavaxer6557 mined isn't working how do I configure it pls

  • @jegans3250
    @jegans3250 4 года назад

    What about away status?

    • @jegans3250
      @jegans3250 4 года назад

      I need that without page refresh without use ajax set time out is that possible?

  • @TungVu-ub1cu
    @TungVu-ub1cu 4 года назад

    No need to reload the page, the way to solve . tks

  • @uroshcs
    @uroshcs 6 лет назад +1

    Useful stuff but you could have explained this in 3 minutes easily.

    • @CodeInspire
      @CodeInspire  6 лет назад +2

      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

    • @uroshcs
      @uroshcs 6 лет назад +1

      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!

    • @CodeInspire
      @CodeInspire  6 лет назад +1

      Sure, he is my favorite tutor too :) . But, he has a lots of experience, I will try your way next time.

    • @JenniferJames-gj4ol
      @JenniferJames-gj4ol 5 лет назад

      @codeinspire u r good n down to earth teacher

  • @elliot6665
    @elliot6665 6 лет назад +1

    cool thx

  • @maddushanmukharao148
    @maddushanmukharao148 Год назад

    How to try

  • @janerosemartinez3247
    @janerosemartinez3247 6 лет назад

    Call to undefined method stdClass::isOnline() i have error of this i follow the tutorial but this is happen

    • @CodeInspire
      @CodeInspire  6 лет назад

      Did you write your isOnline() function . Please re-watch the video, you might have missed something.

    • @janerosemartinez3247
      @janerosemartinez3247 6 лет назад

      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

    • @ermetanyoPh
      @ermetanyoPh 6 лет назад

      Bro ano nilagay mo sa controller mo sa index? $users = Auth::user()? or $users = User::all(); ?

    • @jimburns7549
      @jimburns7549 3 года назад

      @@ermetanyoPh $users = User::get();

    • @jimburns7549
      @jimburns7549 3 года назад

      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'));
      }

  • @Reap3rlotfi
    @Reap3rlotfi 5 лет назад +1

    /**
    * 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

  • @agamurat3019
    @agamurat3019 5 лет назад

    is it realtime

    • @imomer
      @imomer 4 года назад

      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

  • @jholh
    @jholh 5 лет назад

    code please

  • @jaikangammalangmei8271
    @jaikangammalangmei8271 6 лет назад

    please upload source code on github