In this article, We will share with you how to get an IP address in your Laravel application with several way examples.
What is IP address ?
An IP address is a unique numerical label assigned to every device connected to the internet or a local network. It serves as an identifier for the device and allows it to communicate with other devices on the network. IP addresses are written in a dotted-decimal format, which consists of four numbers separated by periods. Each number can range from 0 to 255.
First create controller
php artisan make:controller TestingController
And next go to TestingController and put below code
public function index(Request $request)
{
dd($request->ip());
}
Next go to web.php and put below code
Route::get('ip', [App\Http\Controllers\TestingController::class, 'index']);
Now start the server
php artisan serve
http://127.0.0.1:8000/ip
Now IP address coming successfully šš