File: D:/HostingSpaces/Neopoints/momsecurity.be/app/Testimonials/TestimonialController.php
<?php
namespace App\Testimonials;
use App\Base\Controller;
use App\Buttons\Models\Button;
use App\PostLabels\Models\PostLabel;
use App\Posts\Models\Post;
use App\Testimonials\Models\Testimonial;
use Komma\KMS\Components\ComponentService;
final class TestimonialController extends Controller
{
private $testimonialService;
private $testimonialPaginationKey = 'testimonialPagination';
public function __construct(TestimonialService $testimonialService)
{
parent::__construct();
$this->testimonialService = $testimonialService;
}
/**
* @return \Illuminate\Contracts\View\View
*/
public function index()
{
$page = $this->links->references->node;
$testimonials = $this->testimonialService->getAllTestimonials();
// $testimonials->withPath($this->links->posts->route);
// Make language menu for given page
$languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->{$page->code_name}, $this->links->home);
$this->keepTrackOfPagination($this->testimonialPaginationKey);
// Return view
return view('templates.testimonials_index',[
'page' => $page,
'links' => $this->links,
'languageMenu' => $languageMenu,
'testimonials' => $testimonials,
]);
}
/**
* @param Testimonial $testimonial
* @return \Illuminate\Contracts\View\View
*/
public function show(Testimonial $reference)
{
$testimonial = $reference;
$testimonial->load('translation', 'translations');
$page = $this->links->references->node;
// Make language menu for given page
$languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->{$page->code_name}, $this->links->home);
$componentService = app(ComponentService::class);
$components = $componentService->getViewComponents($testimonial->translation);
// Create previous route for better navigation UX
// $previousRoute = $this->createPreviousRoute($this->postPaginationKey, $this->links->posts->route);
$nextTestimonials = $this->testimonialService->getNextTestimonials($testimonial);
// Return view
return view('templates.testimonials_show',[
'page' => $page,
'testimonial' => $testimonial,
'nextTestimonials' => $nextTestimonials,
'components' => $components,
'links' => $this->links,
'languageMenu' => $languageMenu,
]);
}
}