Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create schema table datatype longtext?

I need some help. Example:

$table->text('description');

But, how to code/write, if I want my datatype is 'LONGTEXT' ?

I unable to find documentation on this @ http://laravel.com/docs/schema

Thanks!

like image 407
claudchan Avatar asked Jun 06 '13 02:06

claudchan


2 Answers

Laravel 4.2 / 5.1+

Simply use the recently added longText method.

Schema::create('posts', function ($table) {
    $table->increments('id');
    $table->integer('user_id');
    // ...
    $table->longText('description');
    // ...
}

Pre-Laravel 4.2 / 5.1

There is no way of doing that with the regular Laravel Schema classes, since it does not implement such type. If you really need it, you could use the Schema class to create the table, and then alter the table using a SQL query to add this field. For instance, you could have:

Schema::create('posts', function ($table) {
    $table->increments('id');
    $table->integer('user_id');
    // ...
    $table->text('description');
    // ...
}

DB::statement('ALTER TABLE `posts` COLUMN `description` `description` LONGTEXT;');
like image 68
rmobis Avatar answered Oct 26 '22 23:10

rmobis


     Schema::table('table_namae', function (Blueprint $table) {
                $table->longText('column_name');
     });
like image 26
kalpana udara Avatar answered Oct 26 '22 23:10

kalpana udara