Factories and seeder
This commit is contained in:
parent
ac06fa1864
commit
a9af6aaeb0
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
use App\Models\School;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
|
@ -13,7 +14,12 @@ return new class extends Migration
|
|||
{
|
||||
Schema::create('students', function (Blueprint $table) {
|
||||
$table->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']);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue