File: D:/HostingSpaces/SBogers10/farmfun.komma.pro/app/Komma/Kiyoh/KiyohComposer.php
<?php
namespace App\Komma\Kiyoh;
use App\Komma\Locations\Models\Location;
use Illuminate\View\View;
final class KiyohComposer
{
/** @var KiyohService */
private $kiyohService;
public function __construct()
{
$this->kiyohService = app()->make(KiyohService::class);
}
public function general(View $view)
{
$view->with('kiyoh', (object) $this->kiyohService->getTotalScore());
}
public function all(View $view)
{
$view->with('reviews', $this->kiyohService->getLastReviews());
}
public function topReviewsAsJson(View $view, int $rating = 9, int $limit = 5): View
{
$reviews = $this->kiyohService->getLastReviews($rating, $limit);
$locations = Location::with('translation')->get();
$mappedReviews = $reviews->map(function ($review) use ($locations) {
return [
'location' => $locations->find($review->location_id)->translation->name,
'rating' => $review->rating,
'date' => $review->created_at->format('Y-m-d'),
'authorName' => $review->payload['author']['name'],
'headline' => $review->payload['headline'],
'text' => $review->payload['text'],
];
});
return $view->with('reviews', json_encode($mappedReviews));
}
}