Add products module #46

This commit is contained in:
2025-11-26 10:05:43 +01:00
parent 155f0d3525
commit 83dd8e9ecb
21 changed files with 607 additions and 50 deletions
+2 -1
View File
@@ -3,6 +3,7 @@
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\Unit;
class LineItemFactory extends Factory
{
@@ -16,7 +17,7 @@ public function definition(): array
'title' => $this->faker->words(3, true),
'description' => $this->faker->sentence(),
'quantity' => $this->faker->numberBetween(1, 10),
'unit' => $this->faker->randomElement(['Stück', 'Stunden', 'Tage', 'pauschal']),
'unit_id' => Unit::factory(),
'price' => $this->faker->randomFloat(2, 10, 500),
];
}
@@ -0,0 +1,26 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\ProductCategory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\ProductCategory>
*/
class ProductCategoryFactory extends Factory
{
protected $model = ProductCategory::class;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => $this->faker->unique()->word()
];
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\Product;
use App\Models\ProductCategory;
use App\Models\Unit;
class ProductFactory extends Factory
{
protected $model = Product::class;
public function definition()
{
return [
'title' => $this->faker->words(3, true),
'description' => $this->faker->optional()->paragraph(),
'notes' => $this->faker->optional()->sentence(),
'vendor_url' => $this->faker->optional()->url(),
'category_id' => ProductCategory::factory(),
'unit_id' => Unit::factory(), // Neue Einheit
'price' => $this->faker->optional()->randomFloat(2, 10, 1000),
'margin' => $this->faker->randomFloat(2, 0.1, 0.5),
'image' => $this->faker->optional()->imageUrl(640, 480, 'products', true)
];
}
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class UnitFactory extends Factory
{
public function definition(): array
{
return [
'name' => $this->faker->unique()->randomElement([
'Stück',
'Stunden',
'Tage',
'pauschal'
]),
'symbol' => $this->faker->lexify('??'),
];
}
}