diff --git a/README.md b/README.md index 4298f51..2cc4d6c 100644 --- a/README.md +++ b/README.md @@ -67,3 +67,11 @@ Test method `test_teams_with_users()`. --- +## Task 6. HasMany - Average from Field Value + +In the route `/countries`, the table should show the countries with average team size. Fix the Controller to load the relationship number, as it is expected in the Blade. + +Test method `test_countries_with_team_size()`. + +--- + diff --git a/app/Http/Controllers/CountryController.php b/app/Http/Controllers/CountryController.php new file mode 100644 index 0000000..2b9be50 --- /dev/null +++ b/app/Http/Controllers/CountryController.php @@ -0,0 +1,16 @@ +hasMany(Team::class); + } +} diff --git a/app/Models/Team.php b/app/Models/Team.php index 52cbeba..c2749d2 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -9,7 +9,7 @@ class Team extends Model { use HasFactory; - protected $fillable = ['name']; + protected $fillable = ['name', 'size']; public function users() { diff --git a/database/migrations/2021_11_22_061400_create_countries_table.php b/database/migrations/2021_11_22_061400_create_countries_table.php new file mode 100644 index 0000000..41702a1 --- /dev/null +++ b/database/migrations/2021_11_22_061400_create_countries_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('name'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('countries'); + } +} diff --git a/database/migrations/2021_11_22_061411_add_country_id_to_teams_table.php b/database/migrations/2021_11_22_061411_add_country_id_to_teams_table.php new file mode 100644 index 0000000..4edb998 --- /dev/null +++ b/database/migrations/2021_11_22_061411_add_country_id_to_teams_table.php @@ -0,0 +1,32 @@ +foreignId('country_id')->nullable()->constrained(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('teams', function (Blueprint $table) { + // + }); + } +} diff --git a/database/migrations/2021_11_22_061647_add_size_to_teams_table.php b/database/migrations/2021_11_22_061647_add_size_to_teams_table.php new file mode 100644 index 0000000..28011bc --- /dev/null +++ b/database/migrations/2021_11_22_061647_add_size_to_teams_table.php @@ -0,0 +1,32 @@ +integer('size')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('teams', function (Blueprint $table) { + // + }); + } +} diff --git a/resources/views/countries/index.blade.php b/resources/views/countries/index.blade.php new file mode 100644 index 0000000..176f214 --- /dev/null +++ b/resources/views/countries/index.blade.php @@ -0,0 +1,5 @@ +