36 lines
1.1 KiB
PHP
36 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Modules\Core\Review\Services;
|
|
|
|
use Illuminate\Support\Facades\Event;
|
|
use Modules\Core\Auth\Models\Staff;
|
|
use Modules\Core\Review\Events\ReviewReplied;
|
|
use Modules\Core\Review\Models\ProductReview;
|
|
|
|
/**
|
|
* The one place a reply is written onto a ProductReview — previously
|
|
* Modules\Core\Review\Filament\Pages\ManageProductReviews wrote directly
|
|
* to the record inside its own Action closure, with no Service and no
|
|
* event dispatched for a real state change (a customer's review getting a
|
|
* staff reply). Matches the write-then-dispatch shape every other
|
|
* module's Service already uses (e.g. Modules\Core\Payment\Services\
|
|
* PaymentMethodService, Modules\Core\Customer\Services\
|
|
* CustomerAccountService).
|
|
*/
|
|
class ReviewService
|
|
{
|
|
public function reply(ProductReview $review, string $reply, Staff $repliedBy): ProductReview
|
|
{
|
|
$wasReply = $review->replied_at === null;
|
|
|
|
$review->update([
|
|
'reply' => $reply,
|
|
'replied_at' => now(),
|
|
]);
|
|
|
|
Event::dispatch(new ReviewReplied($review, $repliedBy, $wasReply));
|
|
|
|
return $review;
|
|
}
|
|
}
|