-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from SethSharp/general-seeding-and-some-product…
…-related General seeding and some product related
- Loading branch information
Showing
24 changed files
with
399 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Products; | ||
|
||
use Inertia\Inertia; | ||
use App\Http\Controllers\Controller; | ||
use App\Domain\Products\Models\Product; | ||
|
||
class IndexProductsController extends Controller | ||
{ | ||
public function __invoke() | ||
{ | ||
return Inertia::render('Products/Index', [ | ||
'products' => Product::with(['file', 'category'])->get() | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Database\Factories\Domain\Files\Models; | ||
|
||
use App\Domain\Files\Models\File; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
class FileFactory extends Factory | ||
{ | ||
protected $model = File::class; | ||
|
||
public function definition(): array | ||
{ | ||
return [ | ||
'path' => $this->image(), | ||
]; | ||
} | ||
|
||
protected function image(): string | ||
{ | ||
$images = [ | ||
'https://tailwindui.com/img/ecommerce-images/product-page-03-related-product-01.jpg' | ||
]; | ||
|
||
return $images[array_rand($images)]; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
database/factories/Domain/Products/Models/ProductFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Database\Factories\Domain\Products\Models; | ||
|
||
use App\Domain\Files\Models\File; | ||
use App\Domain\Products\Models\Product; | ||
use App\Domain\Categories\Models\Category; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
class ProductFactory extends Factory | ||
{ | ||
protected $model = Product::class; | ||
|
||
public function definition(): array | ||
{ | ||
return [ | ||
'file_id' => File::factory()->create(), | ||
'category_id' => Category::factory()->create(), | ||
'title' => $this->faker->title, | ||
'description' => $this->faker->words(12, true), | ||
'price' => $this->faker->numberBetween(10, 100) | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
database/migrations/2023_12_03_014914_create_features_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
return new class() extends Migration { | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('features', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('description'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
}; |
20 changes: 20 additions & 0 deletions
20
database/migrations/2023_12_03_014924_create_product_feature_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
return new class() extends Migration { | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('product_feature', function (Blueprint $table) { | ||
$table->id(); | ||
$table->foreignId('feature_id'); | ||
$table->foreignId('product_id'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Database\Seeders; | ||
|
||
use Illuminate\Database\Seeder; | ||
use App\Domain\Files\Models\File; | ||
use App\Domain\Categories\Models\Category; | ||
|
||
class CategorySeeder extends Seeder | ||
{ | ||
public function run(): void | ||
{ | ||
$numOfCategories = 4; | ||
|
||
$categories = Category::factory()->count($numOfCategories)->create([ | ||
'file_id' => null, | ||
]); | ||
|
||
foreach ($categories as $index => $category) { | ||
$category->update([ | ||
'file_id' => File::factory()->create([ | ||
'path' => '/images/seeding/categories/' . $index + 1 . '.webp' | ||
])->id | ||
]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Database\Seeders; | ||
|
||
use Illuminate\Database\Seeder; | ||
use App\Domain\Files\Models\File; | ||
use App\Domain\Products\Models\Product; | ||
|
||
class ProductTableSeeder extends Seeder | ||
{ | ||
public function run(): void | ||
{ | ||
$productCount = 4; | ||
// loop this over how many files there are and adjust the factory to pass to file factory | ||
$products = Product::factory()->count($productCount)->create(); | ||
|
||
foreach ($products as $index => $product) { | ||
$product->update([ | ||
'file_id' => File::factory()->create([ | ||
'path' => '/images/seeding/categories/' . $index + 1 . '.webp' | ||
])->id, | ||
'category_id' => $index + 1 | ||
]); | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
resources/js/Components/Card/Products/ProductAdminCard.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<script setup> | ||
import { Link } from '@inertiajs/vue3' | ||
import CreateEditProductForm from '@/Components/Products/CreateEditProductForm.vue' | ||
import CreateEditProductModal from '@/Components/Modals/Products/CreateEditProductModal.vue' | ||
import { ref } from 'vue' | ||
defineProps({ | ||
product: Object, | ||
}) | ||
const createEditState = ref(false) | ||
const showState = ref(false) | ||
const toggleCreateEdit = () => { | ||
createEditState.value = !createEditState.value | ||
} | ||
const toggleShow = () => { | ||
showState.value = !showState.value | ||
} | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<div class="relative"> | ||
<div class="relative h-44 w-full overflow-hidden rounded-lg"> | ||
<img | ||
:src="product.file.path" | ||
alt="Product Image" | ||
class="h-full w-full object-cover object-center" | ||
/> | ||
</div> | ||
<div class="relative mt-4"> | ||
<h3 class="text-lg font-medium text-gray-900">{{ product.title }}</h3> | ||
<h3 class="text-sm font-medium text-gray-600">{{ product.category.name }}</h3> | ||
</div> | ||
<div | ||
class="absolute inset-x-0 top-0 flex h-44 items-end justify-end overflow-hidden rounded-lg p-4" | ||
> | ||
<div | ||
aria-hidden="true" | ||
class="absolute inset-x-0 bottom-0 h-36 bg-gradient-to-t from-black opacity-50" | ||
/> | ||
<p class="relative text-lg font-semibold text-white">${{ product.price }}</p> | ||
</div> | ||
</div> | ||
<div class="mt-6"> | ||
<div | ||
@click="toggleCreateEdit" | ||
class="relative flex items-center justify-center rounded-md border border-transparent bg-gray-100 px-8 py-2 text-sm font-medium text-gray-900 hover:bg-gray-200" | ||
> | ||
Edit | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<CreateEditProductModal :state="createEditState" @close="toggleCreateEdit" :product="product" /> | ||
</template> |
29 changes: 29 additions & 0 deletions
29
resources/js/Components/Modals/Products/CreateEditProductModal.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<script setup> | ||
import CreateEditCategoryForm from '@/Components/Categories/CreateEditCategoryForm.vue' | ||
import BaseModal from '@/Components/Modals/BaseModal.vue' | ||
import CreateEditProductForm from '@/Components/Products/CreateEditProductForm.vue' | ||
const props = defineProps({ | ||
state: Boolean, | ||
product: Object, | ||
}) | ||
const emits = defineEmits(['close']) | ||
const title = props.product ? 'Edit ' + props.product.name : 'Create' | ||
const closeModal = () => { | ||
emits('close') | ||
} | ||
</script> | ||
|
||
<template> | ||
<BaseModal :state="state" @close="closeModal"> | ||
<template #title> | ||
{{ title }} | ||
</template> | ||
<template #content> | ||
<CreateEditProductForm :product="product" @close="closeModal" /> | ||
</template> | ||
</BaseModal> | ||
</template> |
Oops, something went wrong.