🌱 🏗️ ⬆️ ✨add expense table 🎨 🔧
This commit is contained in:
28
database/factories/ExpenseFactory.php
Normal file
28
database/factories/ExpenseFactory.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Model>
|
||||
*/
|
||||
class ExpenseFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'id_user' => 1,
|
||||
'id_type_expenses' => 1,
|
||||
'amount' => fake()->randomFloat(),
|
||||
'description' => Str::random(90),
|
||||
'date' => fake()->date(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ class IncomeFactory extends Factory
|
||||
{
|
||||
return [
|
||||
'id_user' => 1,
|
||||
'id_type_income' => 1,
|
||||
'id_type_incomes' => 1,
|
||||
'amount' => fake()->randomFloat(),
|
||||
'description' => Str::random(90),
|
||||
'date' => fake()->date(),
|
||||
|
||||
@@ -11,7 +11,7 @@ return new class extends Migration
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('type_expanses', function (Blueprint $table) {
|
||||
Schema::create('type_expenses', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('label');
|
||||
});
|
||||
@@ -22,6 +22,6 @@ return new class extends Migration
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('type_expanses');
|
||||
Schema::dropIfExists('type_expenses');
|
||||
}
|
||||
};
|
||||
@@ -11,18 +11,18 @@ return new class extends Migration
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('previsional_expanses', function (Blueprint $table) {
|
||||
Schema::create('previsional_expenses', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('id_user');
|
||||
$table->unsignedBigInteger('id_type_expanse');
|
||||
$table->unsignedBigInteger('id_type_expenses');
|
||||
$table->double('amount')->default(0);
|
||||
$table->string('description', 200)->default('');
|
||||
$table->date('date');
|
||||
|
||||
$table->foreign('id_user')
|
||||
->references('id')->on('users');
|
||||
$table->foreign('id_type_expanse')
|
||||
->references('id')->on('type_expanses');
|
||||
$table->foreign('id_type_expenses')
|
||||
->references('id')->on('type_expenses');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
@@ -32,6 +32,6 @@ return new class extends Migration
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('previsional_expanses');
|
||||
Schema::dropIfExists('previsional_expenses');
|
||||
}
|
||||
};
|
||||
@@ -11,18 +11,18 @@ return new class extends Migration
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('expanses', function (Blueprint $table) {
|
||||
Schema::create('expenses', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('id_user');
|
||||
$table->unsignedBigInteger('id_type_expanse');
|
||||
$table->unsignedBigInteger('id_type_expenses');
|
||||
$table->double('amount')->default(0);
|
||||
$table->string('description', 200)->default('');
|
||||
$table->date('date');
|
||||
|
||||
$table->foreign('id_user')
|
||||
->references('id')->on('users');
|
||||
$table->foreign('id_type_expanse')
|
||||
->references('id')->on('type_expanses');
|
||||
$table->foreign('id_type_expenses')
|
||||
->references('id')->on('type_expenses');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
@@ -32,6 +32,6 @@ return new class extends Migration
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('expanses');
|
||||
Schema::dropIfExists('expenses');
|
||||
}
|
||||
};
|
||||
@@ -13,7 +13,7 @@ return new class extends Migration
|
||||
{
|
||||
Schema::create('recurring_expenses', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('id_type_expanse');
|
||||
$table->unsignedBigInteger('id_type_expenses');
|
||||
$table->unsignedBigInteger('id_recurring');
|
||||
$table->unsignedBigInteger('id_user');
|
||||
$table->double('amount')->default(0);
|
||||
@@ -21,8 +21,8 @@ return new class extends Migration
|
||||
$table->date('date');
|
||||
$table->date('end_date')->nullable();
|
||||
|
||||
$table->foreign('id_type_expanse')
|
||||
->references('id')->on('type_expanses');
|
||||
$table->foreign('id_type_expenses')
|
||||
->references('id')->on('type_expenses');
|
||||
$table->foreign('id_recurring')
|
||||
->references('id')->on('recurrings');
|
||||
$table->foreign('id_user')
|
||||
|
||||
@@ -13,7 +13,7 @@ return new class extends Migration
|
||||
{
|
||||
Schema::create('recurring_incomes', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('id_type_expanse');
|
||||
$table->unsignedBigInteger('id_type_expenses');
|
||||
$table->unsignedBigInteger('id_recurring');
|
||||
$table->unsignedBigInteger('id_user');
|
||||
$table->double('amount')->default(0);
|
||||
@@ -21,8 +21,8 @@ return new class extends Migration
|
||||
$table->date('date');
|
||||
$table->date('end_date')->nullable();
|
||||
|
||||
$table->foreign('id_type_expanse')
|
||||
->references('id')->on('type_expanses');
|
||||
$table->foreign('id_type_expenses')
|
||||
->references('id')->on('type_expenses');
|
||||
$table->foreign('id_recurring')
|
||||
->references('id')->on('recurrings');
|
||||
$table->foreign('id_user')
|
||||
|
||||
@@ -14,14 +14,14 @@ return new class extends Migration
|
||||
Schema::create('incomes', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('id_user');
|
||||
$table->unsignedBigInteger('id_type_income');
|
||||
$table->unsignedBigInteger('id_type_incomes');
|
||||
$table->double('amount');
|
||||
$table->string('description', 200)->default('');
|
||||
$table->date('date');
|
||||
|
||||
$table->foreign('id_user')
|
||||
->references('id')->on('users');
|
||||
$table->foreign('id_type_income')
|
||||
$table->foreign('id_type_incomes')
|
||||
->references('id')->on('type_incomes');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
@@ -14,14 +14,14 @@ return new class extends Migration
|
||||
Schema::create('previsional_incomes', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('id_user');
|
||||
$table->unsignedBigInteger('id_type_income');
|
||||
$table->unsignedBigInteger('id_type_incomes');
|
||||
$table->double('amount');
|
||||
$table->string('description', 200)->default('');
|
||||
$table->date('date');
|
||||
|
||||
$table->foreign('id_user')
|
||||
->references('id')->on('users');
|
||||
$table->foreign('id_type_income')
|
||||
$table->foreign('id_type_incomes')
|
||||
->references('id')->on('type_incomes');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
@@ -17,7 +17,9 @@ class DatabaseSeeder extends Seeder
|
||||
$this->call([
|
||||
UserSeeder::class,
|
||||
TypeIncomeSeeder::class,
|
||||
TypeExpenseSeeder::class,
|
||||
IncomeSeeder::class,
|
||||
ExpenseSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
20
database/seeders/ExpenseSeeder.php
Normal file
20
database/seeders/ExpenseSeeder.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Expense;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class ExpenseSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
Expense::factory()
|
||||
->count(50)
|
||||
->create();
|
||||
}
|
||||
}
|
||||
20
database/seeders/TypeExpenseSeeder.php
Normal file
20
database/seeders/TypeExpenseSeeder.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\TypeExpense;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class TypeExpenseSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
TypeExpense::create([
|
||||
'label' => 'test',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user