Fix product resource with comments
This commit is contained in:
parent
0681bf8f0a
commit
6aab7d4eff
2 changed files with 9 additions and 2 deletions
|
|
@ -6,6 +6,7 @@ use App\Enums\Products\ClaimEnum;
|
|||
use App\Enums\Products\OriginEnum;
|
||||
use App\Models\Keyword;
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductComment;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ProductResource extends JsonResource
|
||||
|
|
@ -87,7 +88,13 @@ class ProductResource extends JsonResource
|
|||
'product_range' => $this->product->product_range->label(),
|
||||
'geo_area' => $this->product->geo_area->label(),
|
||||
'freeComment' => $this->product->comment,
|
||||
'productComments' => $this->product->productComments,
|
||||
// FIXME: Use dedicaced resources for relations.
|
||||
'productComments' => $this->product->productComments->map(function (ProductComment $comment) {
|
||||
return (object)\array_merge($comment->toArray(), [
|
||||
'created_at' => $comment->created_at->isoFormat('DD\/MM\/YYYY'),
|
||||
'updated_at' => $comment->updated_at->isoFormat('DD\/MM\/YYYY'),
|
||||
]);
|
||||
}),
|
||||
'productKeywords' => $this->product->productKeywords
|
||||
->map(fn (Keyword $keyword) => $keyword->label)
|
||||
->implode(', '),
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@
|
|||
<p><strong>{{ __('Commentaire libre : ') }}</strong>{{ strip_tags($product->freeComment) }}</p>
|
||||
@endif
|
||||
@foreach ($product->productComments as $productComment)
|
||||
<p><strong>{{ __('Commentaire dégustation du : ') }}</strong>{{ $productComment->created_at->isoFormat('DD\/MM\/YYYY') }}</p>
|
||||
<p><strong>{{ __('Commentaire dégustation du : ') }}</strong>{{ $productComment->created_at }}</p>
|
||||
<table class="table" width="100%">
|
||||
<tr class="table-header">
|
||||
<td class="table-cell-text-center" width="20%"><strong>{{ __('Appréciation') }}</strong></td>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue