Add Notes model, controller and database table. Implement it in Customer Dialog, #6

This commit is contained in:
2025-11-21 13:23:13 +01:00
parent c152842e87
commit 8056c12f6d
11 changed files with 396 additions and 47 deletions
+23
View File
@@ -0,0 +1,23 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Note>
*/
class NoteFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'text' => $this->faker->sentences(2, true),
];
}
}
@@ -22,7 +22,6 @@ public function up()
$table->json('billing_address')->nullable();
$table->foreignId('payment_terms_id')->constrained()->default(3); // Standard-Zahlungsziel: 14 Tage
$table->enum('status', ['active', 'inactive', 'prospect'])->default('active');
$table->text('notes')->nullable();
$table->string('logo')->nullable();
$table->timestamps();
});
@@ -0,0 +1,36 @@
<?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('notes', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->nullOnDelete();
$table->text('text');
// Polymorphische Beziehung
$table->unsignedBigInteger('notable_id');
$table->string('notable_type');
$table->timestamps();
$table->index(['user_id', 'notable_id', 'notable_type']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('notes');
}
};
+10 -2
View File
@@ -6,6 +6,7 @@
use App\Models\User;
use App\Models\Customer;
use App\Models\Contact;
use App\Models\Note;
use App\Models\Invoice;
use App\Models\LineItem;
@@ -21,14 +22,14 @@ public function run(): void
SettingsTableSeeder::class
]);
User::factory()->create([
$user = User::factory()->create([
'name' => 'Daniel Stock',
'email' => 'daniel.stock@tooloop.de',
'password' => bcrypt('6T0az2JGO5oA'),
]);
// Create customers with contacts
Customer::factory(20)->create()->each(function ($customer) {
Customer::factory(20)->create()->each(function ($customer) use ($user) {
// Create a primary contact for each customer
Contact::factory()->create([
'customer_id' => $customer->id,
@@ -39,6 +40,13 @@ public function run(): void
Contact::factory(rand(1, 3))->create([
'customer_id' => $customer->id,
]);
// Create some notes for each customer
Note::factory(rand(0, 5))->create([
'user_id' => $user->id,
'customer_id' => $customer->id,
]);
});
// Create invoices