我在使用 aws、mysql、laravel 和 Angular 时遇到一个奇怪的问题。
我有一个本地运行的 vagrant 实例,上面运行着我的应用程序和数据库。
我在前端使用 Angular,因此当加载视图时,Angular 会请求接收用户输入的所有“目标”的列表。目标中的字段之一是 goalStatus。这是 0 或 1 作为整数存储在 mysql 表中。
角度检查该值是 0 还是 1,并根据结果显示不同的表格单元格,如下所示
<th ng-if="goal.goalStatus === '0'"><p class="text-danger">In Progress</p></th>
<th ng-if="goal.goalStatus === '1'"><p class="text-success">Achieved</p></th>
在 chrome 开发工具中,当我查看此请求的响应结果时,我看到 goalStatus 像这样返回
"goalStatus":"0"
并且角度 if 语句按预期工作。
但是,当我将此应用程序推送到 Elastic beanstalk 中的开发环境(该环境连接到具有相同迁移和播种运行的 mysql rds 实例)时,开发工具显示 goalStatus 如下
"goalStatus":0
并且角度 if 条件不满足,因此两个元素都不显示
因此,在弹性 beanstalk 实例上,它似乎以整数形式返回,但在本地计算机上,它以字符串形式返回。我不知道问题是否出在 mysql、laravel 或其他地方。
有任何想法吗?我已经在下表中包含了 laravel 迁移和种子类,以防万一
移民
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateGoalsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('goals', function(Blueprint $table) {
$table->increments('id');
$table->integer('userId');
$table->string('title');
$table->string('goalDesc');
$table->integer('goalStatus')->nullable();
$table->integer('bodyGoalId')->nullable();
$table->integer('strengthGoalId')->nullable();
$table->integer('distanceGoalId')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('goals');
}
}
seeder
<?php
class GoalsTableSeeder extends Seeder
{
public function run()
{
// Uncomment the below to wipe the table clean before populating
DB::table('goals')->truncate();
$now = date('Y-m-d H:i:s');
$goals = array(array(
'userId' => 1,
'title' => 'first goal title',
'goalDesc' => 'This should describe my goal in text form',
'goalStatus' => 0,
'bodyGoalId' => null,
'strengthGoalId' => null,
'distanceGoalId' => 1,
'created_at' => $now,
'updated_at' => $now),
array(
'userId' => 1,
'title' => 'strength goal title',
'goalDesc' => 'This should describe my strngth goal in text form',
'goalStatus' => 0,
'bodyGoalId' => null,
'strengthGoalId' => 1,
'distanceGoalId' => null,
'created_at' => $now,
'updated_at' => $now),
array(
'userId' => 1,
'title' => 'body goal title',
'goalDesc' => 'This should describe my body goal in text form',
'goalStatus' => 0,
'bodyGoalId' => 1,
'strengthGoalId' => null,
'distanceGoalId' => null,
'created_at' => $now,
'updated_at' => $now)
);
// Uncomment the below to run the seeder
DB::table('goals')->insert($goals);
}
}