Skip to content

Commit

Permalink
Add loan and loan repayment table
Browse files Browse the repository at this point in the history
SagarNaliyapara committed Oct 29, 2022
1 parent 16e280c commit d76b883
Showing 7 changed files with 71 additions and 16 deletions.
9 changes: 9 additions & 0 deletions app/Models/Enums/LoanRepaymentStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace App\Models\Enums;

enum LoanRepaymentStatus
{
case PENDING;
case PAID;
}
10 changes: 10 additions & 0 deletions app/Models/Enums/LoanStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Models\Enums;

enum LoanStatus
{
case PENDING;
case APPROVED;
case PAID;
}
9 changes: 9 additions & 0 deletions app/Models/Enums/UserRole.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace App\Models\Enums;

enum UserRole
{
case USER;
case ADMIN;
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"php": "^8.0.2",
"php": "^8.1",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^9.19",
"laravel/sanctum": "^3.0",
17 changes: 2 additions & 15 deletions database/migrations/2014_10_12_000000_create_users_table.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
<?php

use App\Models\Enums\UserRole;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
@@ -19,18 +15,9 @@ public function up()
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->string('role')->default(UserRole::USER);
$table->rememberToken();
$table->timestamps();
});
}

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

use App\Models\Enums\LoanStatus;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up()
{
Schema::create('loans', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained();
$table->decimal('amount');
$table->integer('term')->comment('stored and calculated based on weekly term');
$table->string('status')->default(LoanStatus::PENDING);
$table->timestamps();
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use App\Models\Enums\LoanRepaymentStatus;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up()
{
Schema::create('loan_repayments', function (Blueprint $table) {
$table->id();
$table->foreignId('loan_id')->constrained();
$table->string('status')->default(LoanRepaymentStatus::PENDING);
$table->timestamps();
});
}
};

0 comments on commit d76b883

Please sign in to comment.