Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VARCHAR max in laravel 5

I have searched all over the web for a tutorial on varchar max. I have even tried

$table->string('name', "MAX");

This gives me an error.

How can I set up varchar max for a blog post for a laravel project. Thanks

like image 471
JP Foster Avatar asked Dec 18 '15 19:12

JP Foster


2 Answers

There is no "max" constant for VARCHAR in MySQL. Instead you need to define the maximum value of the field yourself.

In order to define max length for a text field just provide max length limit as second parameter:

$table->string('name', 64);

It will result in a VARCHAR column being created in your MySQL database. Keep in mind that if max length is very high, a field of different type might be created instead (mediumtext, longtext).

like image 88
jedrzej.kurylo Avatar answered Oct 01 '22 12:10

jedrzej.kurylo


Use text for varchar(max):

$table->text('name');
like image 38
Augusto Russo Avatar answered Oct 01 '22 14:10

Augusto Russo