File: D:/HostingSpaces/SBogers10/boldt.komma.pro/app/Komma/Base/Controller.php
<?php
namespace App\Komma\Base;
use App\Komma\Globalization\Languages\LanguageService;
use App\Komma\Pages\PageService;
use App\Komma\Routes\Models\Route;
use App\Komma\Sites\Models\Site;
use App\Komma\Sites\SiteServiceInterface;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
abstract class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
protected $languageService;
protected $pageService;
protected $links;
protected $baseViewPath = 'site.';
/** @var SiteServiceInterface */
private $siteService;
/** @var Site */
protected $site;
public function __construct()
{
if(\App::runningInConsole()) return;
$this->preventRestRouteFromWorking();
$this->languageService = new LanguageService();
$this->pageService = new PageService();
$this->links = $this->pageService->getAllTranslatedPageRoutes();
$this->siteService = app(SiteServiceInterface::class);
$this->site = $this->siteService->getCurrentSite();
}
/**
* This method will prevent that REST routes are working with the application
* They should be resolved by the middleware
*
*/
private function preventRestRouteFromWorking(){
if (\App::runningInConsole()) return;
$request = request();
// Normally it should be resolved or it's a hard defined route
// Example. contact/process
if(isset($request->resolved) && $request->resolved) return;
else{
// Get segments and path
$path = \Request::path();
$segments = \Request::segments();
// Check if current path is a restfull path, or the first segment of it is
$restRoutes = Route::whereIn('route', [$path, $segments[0]])
->get();
// Rest routes should be empty, or it already should be resolved
if($restRoutes->count() == 0) return;
else{
// If production throw 404
if(\App::environment() == 'production') throw abort(404);
// Else Argument Exception with explanation
else throw new \InvalidArgumentException("Route path or the first segment is listed as an REST route");
}
}
}
}