{"id":4607,"date":"2023-07-09T13:05:28","date_gmt":"2023-07-09T13:05:28","guid":{"rendered":"https:\/\/rengga.dev\/blog\/?p=4607"},"modified":"2023-07-09T13:33:14","modified_gmt":"2023-07-09T13:33:14","slug":"how-to-get-a-client-ip-address-in-laravel","status":"publish","type":"post","link":"https:\/\/rengga.dev\/blog\/how-to-get-a-client-ip-address-in-laravel\/","title":{"rendered":"How to get a Client IP address in Laravel"},"content":{"rendered":"<h2>What is an IP Address?<\/h2>\n<p>An Internet Protocol(IP) address also known as a logical address is given by the internet service provider(ISP) which uniquely identifies a system over the network. IP address keeps on changing from time to time.<\/p>\n<h2>Example<\/h2>\n<div class=\"su-button-center\"><a href=\"https:\/\/webtools.rengga.dev\/tool\/whats-my-ip\" class=\"su-button su-button-style-glass su-button-wide\" style=\"color:#FFFFFF;background-color:#068C45;border-color:#057038;border-radius:50px\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"color:#FFFFFF;padding:8px 24px;font-size:18px;line-height:27px;border-color:#51af7d;border-radius:50px;text-shadow:1px 1px 1px #000000\"><i class=\"sui sui-link\" style=\"font-size:18px;color:#FFFFFF\"><\/i> Whats my IP<\/span><\/a><\/div>\n<p>&nbsp;<\/p>\n<h2>How to get a Client IP address in Laravel?<\/h2>\n<p>For getting the IP Address we have to include\u00a0<strong>use Illuminate\\Http\\Request;<\/strong>\u00a0in the controller and then add the code of the below pre tag. It will give the IP address of the network.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">$clientIP = request()-&gt;ip();\r\ndd($clientIP);<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">public function index(Request $request){\r\n  dd($request-&gt;ip());\r\n}\r\n$clientIP = \\Request::ip();\r\ndd($clientIP);\r\n$clientIP = \\Request::getClientIp(true);\r\ndd($clientIP);<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>What is an IP Address? An Internet Protocol(IP) address also known as <a class=\"read-more\" href=\"https:\/\/rengga.dev\/blog\/how-to-get-a-client-ip-address-in-laravel\/\" title=\"How to get a Client IP address in Laravel\" itemprop=\"url\"><\/a><\/p>\n","protected":false},"author":1,"featured_media":4608,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[673,674,675,676],"newstopic":[597,574],"class_list":{"0":"post-4607","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-web-development","8":"tag-client-ip-address","9":"tag-ip-address-in-laravel","10":"tag-laravel-code","11":"tag-rengga-dev","12":"newstopic-laravel","13":"newstopic-php"},"_links":{"self":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts\/4607","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/comments?post=4607"}],"version-history":[{"count":2,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts\/4607\/revisions"}],"predecessor-version":[{"id":4610,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts\/4607\/revisions\/4610"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/media\/4608"}],"wp:attachment":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/media?parent=4607"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/categories?post=4607"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/tags?post=4607"},{"taxonomy":"newstopic","embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/newstopic?post=4607"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}