Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create signed increments in Laravel's Schema?

Tags:

php

laravel

I have the following in my migration file:

public function up()
{
   Schema::create('Users', function($table)
   {
      $table->engine='InnoDB';
      $table->increments('id');
      $table->string('name', 255);
   });
}

So far the whole application used signed ids, and I don't want to break this so how can I make them signed? I know that the default value is unsigned and that there is a ->unsigned() modifier (that I don't understand whats is for if this is the default value) but from this I supposed there is a ->signed() too, but there isn't. The following code runs without errors but the id is still unsigned when I watch it in phpMyAdmin:

Schema::create('Users', function($table)
{
   $table->engine='InnoDB';
   $table->increments('id')->signed();
   $table->string('name', 255);
});

I searched the official and a non official documentation but none of them mentioned anything about this. So how can I make it signed?

like image 886
totymedli Avatar asked Mar 20 '23 20:03

totymedli


1 Answers

An integer column set to auto-increment should do just the trick if you also want it signed.

$table->integer('id', true);

From: framework/src/Illuminate/Database/Schema/Blueprint.php

/**
 * Create a new integer column on the table.
 *
 * @param  string  $column
 * @param  bool  $autoIncrement
 * @param  bool  $unsigned
 * @return \Illuminate\Support\Fluent
 */
public function integer($column, $autoIncrement = false, $unsigned = false)
{
  return $this->addColumn('integer', $column, compact('autoIncrement', 'unsigned'));
}
like image 175
random Avatar answered Apr 01 '23 16:04

random