Skip to content

Commit 355bc90

Browse files
committed
Adds Transaction seeder and table
1 parent 738f9ac commit 355bc90

File tree

5 files changed

+84
-1
lines changed

5 files changed

+84
-1
lines changed

app/Http/Controllers/DashboardController.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
namespace App\Http\Controllers;
44

5+
use Illuminate\View\View;
6+
57
class DashboardController extends Controller
68
{
7-
public function index()
9+
public function index(): View
810
{
911
return view('app');
1012
}

app/Models/Transaction.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
6+
use Illuminate\Database\Eloquent\Factories\HasFactory;
7+
use Illuminate\Database\Eloquent\Model;
8+
use Illuminate\Database\Eloquent\SoftDeletes;
9+
10+
class Transaction extends Model
11+
{
12+
use HasFactory,SoftDeletes;
13+
14+
protected $guarded =[];
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('transactions', function (Blueprint $table) {
15+
$table->id();
16+
$table->string('title');
17+
$table->string('description');
18+
$table->double('credit', 10, 2);
19+
$table->double('debit', 10, 2);
20+
$table->string('status');
21+
$table->timestamps();
22+
$table->softDeletes();
23+
});
24+
}
25+
26+
/**
27+
* Reverse the migrations.
28+
*/
29+
public function down(): void
30+
{
31+
Schema::dropIfExists('transaction');
32+
}
33+
};

database/seeders/DatabaseSeeder.php

+4
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@ public function run(): void
1818
// 'name' => 'Test User',
1919
// 'email' => '[email protected]',
2020
// ]);
21+
22+
$this->call([
23+
TransactionSeeder::class,
24+
]);
2125
}
2226
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Database\Seeders;
4+
5+
use App\Models\Transaction;
6+
use Faker\Factory;
7+
use Illuminate\Database\Seeder;
8+
9+
class TransactionSeeder extends Seeder
10+
{
11+
/**
12+
* Run the database seeds.
13+
*
14+
* @return void
15+
*/
16+
public function run()
17+
{
18+
for ($i=0; $i <5 ; $i++) {
19+
Transaction::create([
20+
'title' => Factory::create()->name(),
21+
'description' => Factory::create()->text(),
22+
'credit' => rand(0,1),
23+
'debit' => rand(0,1),
24+
'status' => Factory::create()->randomElement(['Success', 'Failed', 'Pending'])
25+
]);
26+
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)