diff --git a/app/Models/School.php b/app/Models/School.php index 9d6b9b2..c1e9941 100644 --- a/app/Models/School.php +++ b/app/Models/School.php @@ -16,6 +16,10 @@ class School extends Model { return $this->hasMany(User::class); } + public function users(): HasMany + { + return $this->hasMany(User::class); + } public function emailDomains(): HasMany { return $this->hasMany(SchoolEmailDomain::class); @@ -27,4 +31,9 @@ class School extends Model $img .= substr($this->name,0,1); return $img; } + + public function students(): HasMany + { + return $this->hasMany(Student::class); + } } diff --git a/app/Models/Student.php b/app/Models/Student.php index 7abf19a..c821523 100644 --- a/app/Models/Student.php +++ b/app/Models/Student.php @@ -4,8 +4,15 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class Student extends Model { use HasFactory; + + public function school(): BelongsTo + { + return $this->belongsTo(School::class); + } + } diff --git a/app/Models/User.php b/app/Models/User.php index 02104d7..41d9828 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -81,12 +81,5 @@ class User extends Authenticatable implements MustVerifyEmail return $return; } return SchoolEmailDomain::with('school')->where('domain','=',$this->emailDomain())->get(); -// $x = SchoolEmailDomain::with('school')->where('domain','=',Auth::user()->emailDomain())->get(); -// $possibilities = SchoolEmailDomain::with('school')->where('domain','=', $this->emailDomain())->getModels(); -// $return = []; -// foreach ($possibilities as $possibility) { -// $return[] = $possibility->school; -// } -// return $return; } } diff --git a/database/factories/SchoolFactory.php b/database/factories/SchoolFactory.php index 20a3631..03cf831 100644 --- a/database/factories/SchoolFactory.php +++ b/database/factories/SchoolFactory.php @@ -17,7 +17,11 @@ class SchoolFactory extends Factory public function definition(): array { return [ - // + 'name' => fake()->city(), + 'address' => fake()->address(), + 'city' => fake()->city(), + 'state' => 'OK', + 'zip' => rand(73001, 74999), ]; } } diff --git a/database/factories/StudentFactory.php b/database/factories/StudentFactory.php index b2fb77e..44ed7c1 100644 --- a/database/factories/StudentFactory.php +++ b/database/factories/StudentFactory.php @@ -17,7 +17,9 @@ class StudentFactory extends Factory public function definition(): array { return [ - // + 'first_name' => fake()->firstName(), + 'last_name' => fake()->lastName(), + 'grade' => rand(7,12), ]; } } diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index bc73ef4..5c234c8 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -27,7 +27,7 @@ class UserFactory extends Factory return [ 'first_name' => fake()->firstName(), 'last_name' => fake()->lastName(), - 'email' => fake()->unique()->safeEmail(), + 'email' => fake()->unique()->email(), 'judging_preference' => fake()->randomElement($judingPrefPossibilities), 'cell_phone' => fake()->phoneNumber(), 'profile_image_url' => 'https://picsum.photos/200', diff --git a/database/migrations/2024_05_29_043025_create_students_table.php b/database/migrations/2024_05_29_043025_create_students_table.php index feeac2a..62e5775 100644 --- a/database/migrations/2024_05_29_043025_create_students_table.php +++ b/database/migrations/2024_05_29_043025_create_students_table.php @@ -1,5 +1,6 @@ id(); + $table->foreignIdFor(School::class)->constrained()->cascadeOnUpdate()->restrictOnDelete(); + $table->string('first_name'); + $table->string('last_name'); + $table->integer('grade'); $table->timestamps(); + $table->unique(['school_id','first_name','last_name']); }); } diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index d01a0ef..e95104d 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -2,6 +2,8 @@ namespace Database\Seeders; +use App\Models\School; +use App\Models\Student; use App\Models\User; // use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; @@ -15,9 +17,31 @@ class DatabaseSeeder extends Seeder { // User::factory(10)->create(); - User::factory()->create([ - 'name' => 'Test User', - 'email' => 'test@example.com', +// User::factory()->create([ +// 'name' => 'Test User', +// 'email' => 'test@example.com', +// ]); + + $vinita = School::factory()->has(Student::factory()->count(38))->create([ + 'name' => 'Vinita', + 'address' => '801 N. Adair St.', + 'city' => 'Vinita', + 'state' => 'OK', + 'zip'=> '74301' ]); + + $matt = User::factory()->create([ + 'school_id' => $vinita->id, + 'first_name' => 'Matt', + 'last_name' => 'Young', + 'judging_preference' => 'Admin', + 'cell_phone' => '918-994-2263', + 'email' => 'youngma@vinitahornets.com', + 'password' => '$2y$12$sBXf1PnwrLbFQBVxN934O.21jRrm8KVXTlOABxif48Dfbe3Fejv5a' + ]); + + School::factory()->has(Student::factory()->count(random_int(12,45)))->has(User::factory()->count(2))->count(30)->create(); + + } }