Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Laravel migration ip type ipv6 ready?

I need to save Ip's in the database. I am using laravel but I need to store IPv6 and IPv4 ip's Is the ip type ready for IP?

$table->ipAddress('visitor');

Or do I need to use a the normal string type.

Thanks

like image 394
KBeckers Avatar asked Jul 08 '16 17:07

KBeckers


People also ask

What is the advantage of Laravel migrations?

Advantages and Disadvantages of Laravel MigrationIt is a new framework. Web applications can be built on it quickly. It is easy to learn. The documentation is easily available.

What is difference between seeder and migration in Laravel?

Migrations are for creating/altering/deleting tables. Seeds are for filling those tables with data.

How do I change the data type in Laravel migration?

How to change data type of column in laravel 9 migration ? Step 1 : Install doctrine/dbal package. Step 2 : Generate migration file. Step 3 : Open generated migration file and update.

How does migration work in Laravel?

Laravel Migration is an essential feature in Laravel that allows you to create a table in your database. It allows you to modify and share the application's database schema. You can modify the table by adding a new column or deleting an existing column.


1 Answers

The ipAddress() method creates the following field types for the specified databases:

  • MySql - varchar(45)
  • SqlServer - nvarchar(45)
  • Postgres - inet
  • SqlLite - varchar

For text fields, the maximum length needed to store IPv6 addresses is 45 characters, so it looks like this is taken into account for MySql, SqlServer, and SqlLite. Additionally, the inet field in Postgres handles both IPv4 and IPv6 fields.

Considering all this, I'd say it is safe to assume the ipAddress() method will create a field that can handle IPv6 in any database.

like image 153
patricus Avatar answered Sep 21 '22 01:09

patricus