Sometimes we need to store the user's IP address or the mac address of a device in the Laravel application's database. So in this tutorial, I will show you how to define the IP address and Mac addresses column type in the Laravel application. So we need to define column type in the database migration schema.

To define the IP address and mac address column type in Laravel migration, follow the below instruction:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->ipAddress('visitor');
            $table->macAddress('device');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
};

 

Conclusion

I have tried to discuss the clear concept of ip address column type laravel 9. Now we know ip address column type laravel 9. Hope this ip address column type laravel 9 tutorial will help you.