File: D:/HostingSpaces/SBogers10/werkenbij.komma.pro/app/Komma/Buttons/ButtonController.php
<?php
namespace App\Komma\Buttons;
use App\Komma\Base\Controller;
use App\Komma\Buttons\Models\Button;
final class ButtonController extends Controller
{
private $buttonService;
public function __construct(ButtonService $buttonService)
{
parent::__construct();
$this->buttonService = $buttonService;
}
/**
* @return \Illuminate\Contracts\View\View
*/
public function index()
{
$page = $this->pageService->getPageByCodeName('buttons');
$otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page);
$buttons = $this->buttonService->getAllButtons(true);
$buttons->withPath('/' . $this->links->buttons->route);
// Return view
return view('site.templates.buttons_index',[
'page' => $page,
'links' => $this->links,
'otherLanguages' => $otherLanguageRoutes,
'buttons' => $buttons,
]);
}
/**
* @return \Illuminate\Contracts\View\View
*/
public function filters()
{
$filters = request('filters');
dd('customize filter function in ButtonController');
// if (sizeof($filters) != 1) {
// throw abort(404);
// }
// $categoryName = $filters[0];
//
// // Check if category exist else trow 404
// if ( ! $category = ButtonCategoryTranslation::where('slug', $categoryName)
// ->with('translatable')
// ->first()) {
// throw abort(404);
// }
//
// $page = $this->pageService->getPageByCodeName('blog');
// $otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page);
//
// //Get buttons through the category
// $buttons = $category->translatable->buttons()->paginate(8);
// $buttons->withPath('/' . $this->links->blog->route . '/' . $category->slug);
//
//
// // Return view
// return view($this->baseViewPath.$this->pagePrefix.'index',[
// 'page' => $page,
// 'links' => $this->links,
// 'otherLanguages' => $otherLanguageRoutes,
// 'buttons' => $buttons,
// ]);
}
/**
* @param Button $button
* @return \Illuminate\Contracts\View\View
*/
public function show(Button $button)
{
$button->load('translation','translations', 'sites');
// This checks if the button belongs to the set site
if(! $button->sites->contains($this->site)) throw abort(404);
$page = $this->pageService->getPageByCodeName('buttons');
$otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page, $button);
// Return view
return view('site.templates.buttons_show',[
'page' => $page,
'button' => $button,
'links' => $this->links,
'otherLanguages' => $otherLanguageRoutes
]);
}
}