ALTER TABLE migration_demo CHANGE type demo_type INT DEFAULT 0 NOT NULL
ALTER TABLE migration_demo CHANGE type type BIGINT DEFAULT 0 NOT NULL
//无效方式2
Schema::table('migration_demo', function (Blueprint $table) {
$table->bigInteger('type')->default('0')->change()->renameColumn('type', 'demo_type');
});
执行语句 ,rename并没有生效
ALTER TABLE migration_demo CHANGE type type BIGINT DEFAULT 0 NOT NULL
同一字段执行多种变更,正确的方式
Schema::table('demo', function (Blueprint $table) {
$table->renameColumn('name', 'demo_name');
});
Schema::table('demo', function (Blueprint $table) {
$table->string('demo_name', 255)->default('')->change();
});
执行语句结果
ALTER TABLE demo CHANGE demo_name demo_name VARCHAR(255) DEFAULT '' NOT NULL COLLATE utf8mb4_unicode_ci
ALTER TABLE demo CHANGE name demo_name VARCHAR(20) DEFAULT '' NOT NULL
Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables;
/**
* Bootstrap the given application.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @return void
*/
public function bootstrap(Application $app)
{
//此处判断是否开启缓存配置,开启缓存配置直接返回缓存中的配置
//因此开启缓存配置后,env()函数会失效
if ($app->configurationIsCached()) {
return;
}
$this->checkForSpecificEnvironmentFile($app);
//此处加载.env中的文件
try {
(new Dotenv($app->environmentPath(), $app->environmentFile()))->load();
} catch (InvalidPathException $e) {
//
}
}
/**
* Gets the value of an environment variable.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
function env($key, $default = null)
{
$value = getenv($key);
if ($value === false) {
return value($default);
}
switch (strtolower($value)) {
case 'true':
case '(true)':
return true;
case 'false':
case '(false)':
return false;
case 'empty':
case '(empty)':
return '';
case 'null':
case '(null)':
return;
}
if (strlen($value) > 1 && Str::startsWith($value, '"') && Str::endsWith($value, '"')) {
return substr($value, 1, -1);
}
return $value;
}
/**
* Get / set the specified configuration value.
*
* If an array is passed as the key, we will assume you want to set an array of values.
*
* @param array|string $key
* @param mixed $default
* @return mixed|\Illuminate\Config\Repository
*/
function config($key = null, $default = null)
{
if (is_null($key)) {
return app('config');
}
if (is_array($key)) {
return app('config')->set($key);
}
return app('config')->get($key, $default);
}
//app('config) 生成的是 Illuminate\Config\Repository 实例
/**
* Get a generator for the given query.
*
* @return \Generator
*/
public function cursor()
{
foreach ($this->applyScopes()->query->cursor() as $record) {
yield $this->model->newFromBuilder($record);
}
}
chunk() 分块处理 适用于小数据量快速处理
Flight::chunk(200, function ($flights) {
foreach ($flights as $flight) {
//
}
});
内部实现 do while 循环 执行的分页查询sql 耗时和消耗内存取决分块数量,分块数量越大消耗内存和耗时相应减少
select * from `flights` order by `flights`.`id` asc limit 200 offset 0
select * from `flights` order by `flights`.`id` asc limit 200 offset 200
select * from `flights` order by `flights`.`id` asc limit 200 offset 400