-
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 #132 from semanadeinformatica/feature/shop
Shop
- Loading branch information
Showing
15 changed files
with
277 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use Inertia\Inertia; | ||
|
||
class ShopController extends Controller | ||
{ | ||
public function show(Request $request) | ||
{ | ||
$edition = $request->input('edition'); | ||
|
||
if ($edition === null) { | ||
return response('No edition found', 500); | ||
} | ||
|
||
return Inertia::render('Shop', [ | ||
'products' => $edition->products, | ||
]); | ||
} | ||
} |
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,70 @@ | ||
<?php | ||
|
||
namespace App\Traits; | ||
|
||
use Illuminate\Database\Eloquent\Casts\Attribute; | ||
use Illuminate\Http\UploadedFile; | ||
use Illuminate\Support\Facades\Storage; | ||
|
||
trait HasImageProduct | ||
{ | ||
/** | ||
* Update the user's CV. | ||
* | ||
* @param string $storagePath | ||
* @return void | ||
*/ | ||
public function updateImageProduct(UploadedFile $image, $storagePath = 'product-images') | ||
{ | ||
|
||
tap($this->image_path, function ($previous) use ($image, $storagePath) { | ||
if ($previous) { | ||
Storage::disk($this->ImageProductDisk())->delete($previous); | ||
} | ||
|
||
$this->forceFill([ | ||
'image_path' => $image->storePublicly( | ||
$storagePath, ['disk' => $this->ImageProductDisk()] | ||
), | ||
])->save(); | ||
}); | ||
} | ||
|
||
/** | ||
* Delete the user's CV. | ||
* | ||
* @return void | ||
*/ | ||
public function deleteImageProduct() | ||
{ | ||
if (is_null($this->image_path)) { | ||
return; | ||
} | ||
|
||
Storage::disk($this->ImageProductDisk())->delete($this->image_path); | ||
|
||
$this->forceFill([ | ||
'image_path' => null, | ||
])->save(); | ||
} | ||
|
||
/** | ||
* Get the URL to the user's CV. | ||
*/ | ||
public function ImageProductUrl(): Attribute | ||
{ | ||
return Attribute::get(function () { | ||
return Storage::disk($this->ImageProductDisk())->url($this->image_path); | ||
}); | ||
} | ||
|
||
/** | ||
* Get the disk that CVs should be stored on. | ||
* | ||
* @return string | ||
*/ | ||
protected function ImageProductDisk() | ||
{ | ||
return config('jetstream.product_image_disk', 'public'); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -78,5 +78,6 @@ | |
|
||
'profile_photo_disk' => 'public', | ||
'cv_disk' => 'public', | ||
'product_image_disk' => 'public', | ||
|
||
]; |
28 changes: 28 additions & 0 deletions
28
database/migrations/2023_09_27_131517_add_product_image.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,28 @@ | ||
<?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::table('products', function (Blueprint $table) { | ||
$table->string('image_path', 2048)->nullable(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::table('products', function (Blueprint $table) { | ||
$table->dropColumn('image_path'); | ||
}); | ||
} | ||
}; |
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,51 @@ | ||
<script setup lang="ts"> | ||
import type Product from "@/Types/Product"; | ||
import PrimaryButton from "@/Components/PrimaryButton.vue"; | ||
import { ref } from "vue"; | ||
import { VueFinalModal } from "vue-final-modal"; | ||
import "vue-final-modal/style.css"; | ||
const options = ref({ | ||
modelValue: false, | ||
}); | ||
interface Props { | ||
product: Product; | ||
} | ||
defineProps<Props>(); | ||
</script> | ||
|
||
<template> | ||
<div class="flex max-w-[20em] flex-col border-2 border-black"> | ||
<img | ||
class="h-[20em] max-w-[20em] border-b-2 border-black object-cover" | ||
:src="product.image_product_url" | ||
/> | ||
<div | ||
class="flex cursor-pointer flex-col bg-2023-orange px-4 py-2 text-white" | ||
@click="options.modelValue = true" | ||
> | ||
<h2 class="text-xl font-bold">{{ product.name }}</h2> | ||
<div class="flex flex-row gap-2 self-end text-xl"> | ||
<p>{{ product.price }}</p> | ||
<img class="w-5" src="/images/cy-sinf-small.svg" /> | ||
</div> | ||
</div> | ||
</div> | ||
<VueFinalModal | ||
v-model="options.modelValue" | ||
class="flex items-center justify-center" | ||
content-class="max-w-xl mx-4 p-4 bg-2023-bg border border-black border-solid flex relative justify-center items-center flex-col gap-8" | ||
> | ||
<img | ||
:src="product.image_product_url" | ||
class="w-auto justify-center border border-solid border-black shadow-xl shadow-2023-teal-dark" | ||
/> | ||
<p> | ||
Confirmar compra de <b>{{ product.name }}</b> por | ||
{{ product.price }}? | ||
</p> | ||
<PrimaryButton> Comprar </PrimaryButton> | ||
</VueFinalModal> | ||
</template> |
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
Oops, something went wrong.