📅  最后修改于: 2023-12-03 15:20:38.066000             🧑  作者: Mango
In Laravel, TinyInteger is a data type used to store small whole numbers (up to 127) in a database table column. This data type is useful when you only need to store limited data and want to save space in your database.
The TinyInteger data type is supported by Laravel's schema builder and migration system, making it easy to use in your database design.
To use TinyInteger in Laravel, simply use the tinyInteger()
method when creating a new column in a database migration.
Schema::create('users', function (Blueprint $table) {
$table->tinyInteger('age');
});
You can also specify the column size by passing an argument to the tinyInteger()
method. The default size is 1.
$table->tinyInteger('age', 3);
Here is an example of how you can use TinyInteger in a Laravel migration.
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->tinyInteger('age', 3);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
TinyInteger is a useful data type that can help you save space in your database when you only need to store small whole numbers. Laravel's support for TinyInteger in its schema builder and migration system makes it easy to use in your application.