laravel returns json string on local machine but integer on elastic beanstalk instance
angularjs, json, laravel-4, mysql, php
Solution
So this appears to be an issue with the php mysql driver returning all fields as strings regardless of type. source
My aws elastic beanstalk instance seems to be setup to account for this so it is returning strings and strings and ints as ints whereas my vagrant setup needed to be changed to use php5_mysqlnd driver instead of the one it had and this resolved the issue
Problem
I am having a strange problem with aws, mysql, laravel and angular. I have a vagrant instance running locally with both my app and database running on it. I am using angular on the front-end so when the view is loaded angular makes a request to receive a list of all 'goals' entered by the user. one of the fields in goals is goalStatus. this is either 0 or 1 stored as an integer in the mysql table. angular checks if this value is 0 or 1 and displays and different table cell depending on the result like so ``` <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> ``` in chrome dev tools when I look at the response result for this request I see goalStatus being returned like so ``` "goalStatus":"0" ``` and the angular if statements work as intended. however when I push this app to a development environment in elastic beanstalk which connects to a mysql rds instance that has the same migrations and seeding run on it dev tools shows goalStatus as this ``` "goalStatus":0 ``` and the angular if conditions are not met so neither one of the elements displays So it seems that on the elastic beanstalk instance it is being returned as an integer but on the local machine it is being returned as a string. I dont know weather the problem would be in mysql, laravel, or somewhere else. any ideas? I have included the laravel migration and seed classes for the table below just in case migration ``` 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); } } ```