From d99d25f770df1fb3b7aff2c75793e271cad905af Mon Sep 17 00:00:00 2001 From: Matt Young Date: Mon, 27 May 2024 21:02:57 -0500 Subject: [PATCH] Begin working on schools --- app/Http/Controllers/SchoolController.php | 10 +++++ app/Models/School.php | 11 ++++++ app/Models/User.php | 6 +++ database/factories/SchoolFactory.php | 23 ++++++++++++ .../0001_01_01_000000_create_users_table.php | 1 + ...2024_05_27_233356_create_schools_table.php | 37 +++++++++++++++++++ database/seeders/SchoolSeeder.php | 17 +++++++++ 7 files changed, 105 insertions(+) create mode 100644 app/Http/Controllers/SchoolController.php create mode 100644 app/Models/School.php create mode 100644 database/factories/SchoolFactory.php create mode 100644 database/migrations/2024_05_27_233356_create_schools_table.php create mode 100644 database/seeders/SchoolSeeder.php diff --git a/app/Http/Controllers/SchoolController.php b/app/Http/Controllers/SchoolController.php new file mode 100644 index 0000000..a2a12b2 --- /dev/null +++ b/app/Http/Controllers/SchoolController.php @@ -0,0 +1,10 @@ +first_name . ' ' . $this->last_name; } + + public function school(): BelongsTo + { + return $this->belongsTo(School::class); + } } diff --git a/database/factories/SchoolFactory.php b/database/factories/SchoolFactory.php new file mode 100644 index 0000000..20a3631 --- /dev/null +++ b/database/factories/SchoolFactory.php @@ -0,0 +1,23 @@ + + */ +class SchoolFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + // + ]; + } +} diff --git a/database/migrations/0001_01_01_000000_create_users_table.php b/database/migrations/0001_01_01_000000_create_users_table.php index 8bf67b9..da23e33 100644 --- a/database/migrations/0001_01_01_000000_create_users_table.php +++ b/database/migrations/0001_01_01_000000_create_users_table.php @@ -1,5 +1,6 @@ id(); + $table->string('name'); + $table->string('address')->nullable(); + $table->string('city')->nullable(); + $table->string('state')->nullable(); + $table->integer('zip')->nullable(); + $table->timestamps(); + }); + + Schema::table('users', function(Blueprint $table) { + $table->foreignIdFor(School::class)->nullable()->after('id')->constrained()->onUpdate('cascade')->onDelete('set null'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('schools'); + } +}; diff --git a/database/seeders/SchoolSeeder.php b/database/seeders/SchoolSeeder.php new file mode 100644 index 0000000..cb422f8 --- /dev/null +++ b/database/seeders/SchoolSeeder.php @@ -0,0 +1,17 @@ +