How can we get the IP address of the user in Laravel

Laravel get ip address from request

Hello friend in this post I going to show you how to get users Ip address in Laravel 5.4 and save it is database.

  public function trackUserActivity(Request $request){
  
   $user_activity=new UserActivity();
   
   // getting  logged in user info from laravel Auth
    
    $user_activity->user_id=Auth::id();
   
    // Getting ip address of remote user
   
    $user_activity->ip_address=$request->ip();
    
    $user_activity->save();
    
   }
   

Leave a Reply

Your email address will not be published. Required fields are marked *