Skip to content

Commit

Permalink
feat: donors modeling
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhe4rt committed May 31, 2023
1 parent 33722ae commit c7ef23a
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 0 deletions.
23 changes: 23 additions & 0 deletions app/Models/Donor/Donor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Models\Donor;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Donor extends Model
{
use HasFactory;

protected $table = 'donors';

protected $fillable = [
'status_id',
'name',
'email',
'full_address',
'job_title',
'social_type',
'social_url'
];
}
17 changes: 17 additions & 0 deletions app/Models/Donor/Status.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Models\Donor;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Status extends Model
{
use HasFactory;

protected $table = 'donation_statuses';

protected $fillable = [
'name'
];
}
25 changes: 25 additions & 0 deletions database/factories/Donor/DonorFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Database\Factories\Donor;

use App\Models\Donor\Donor;
use App\Models\Donor\Status;
use Illuminate\Database\Eloquent\Factories\Factory;

class DonorFactory extends Factory
{
protected $model = Donor::class;

public function definition(): array
{
return [
'status_id' => Status::factory(),
'name' => $this->faker->name(),
'email' => $this->faker->unique()->email(),
'full_address' => $this->faker->address(),
'job_title' => 'Developer',
'social_type' => $this->faker->randomElement(['twitter', 'github', 'instagram']),
'social_url' => $this->faker->url()
];
}
}
17 changes: 17 additions & 0 deletions database/factories/Donor/StatusFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Database\Factories\Donor;

use App\Models\Donor\Status;
use Illuminate\Database\Eloquent\Factories\Factory;

class StatusFactory extends Factory
{
protected $model = Status::class;
public function definition(): array
{
return [
'name' => $this->faker->name()
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('donation_statuses', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('donation_statuses');
}
};
34 changes: 34 additions & 0 deletions database/migrations/2023_05_31_190034_create_donors_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('donors', function (Blueprint $table) {
$table->id();
$table->foreignId('status_id')->constrained('donation_statuses');
$table->string('name');
$table->string('email');
$table->string('full_address')->comment('City, State / Country');
$table->string('job_title');
$table->string('social_type')->nullable();
$table->string('social_url')->nullable();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('donors');
}
};
22 changes: 22 additions & 0 deletions database/seeders/DonorStatusSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Database\Seeders;

use App\Models\Donor\Status;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class DonorStatusSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$donationStatuses = ['Pending', 'Accepted', 'Rejected'];

foreach($donationStatuses as $donationStatus) {
Status::query()->create(['name' => $donationStatus]);
}
}
}

0 comments on commit c7ef23a

Please sign in to comment.