File: D:/HostingSpaces/SBogers10/zuiderbos.komma.pro/app/Komma/Routes/RouteResolver.php
<?php
namespace Komma\Routes;
class RouteResolver
{
/**
* Resolve route
*
* @return bool
*/
public function resolve()
{
// Return false when we are in the control panel
// $this->redirectToHttps();
//$this->checkOtherDomains();
if ($this->isControlPanel()) {
return false;
}
\Route::get('dienstverlening/{pt1?}/{pt2?}', function ($pt1 = null, $pt2 = null) {
$redirectUrl = 'opleiding-cursussen-arrangementen';
if ($pt1) {
$redirectUrl .= '/'.$pt1;
}
if ($pt2) {
$redirectUrl .= '/'.$pt2;
}
return \Redirect::to($redirectUrl, 301);
});
\Route::get('/_debugbar/assets/stylesheets', [
'as' => 'debugbar-css',
'uses' => '\Barryvdh\Debugbar\Controllers\AssetController@css',
]);
\Route::get('/_debugbar/assets/javascript', [
'as' => 'debugbar-js',
'uses' => '\Barryvdh\Debugbar\Controllers\AssetController@js',
]);
// Sitemap
\Route::get('{schoolName}/sitemap', 'Komma\Sitemap\SitemapController@showSchoolSitemap');
// Search
\Route::get('{site}/zoekresultaten', 'Komma\Search\SearchController@show');
// Maybe we are receiving an alias
// Check for a REST-route that belongs to this alias and dispatch a new Request
\Route::get(\Request::path(), function () {
// Return a 404 when the alias is not found in the database
if (! $dispatch = $this->dispatchRoute()) {
\App::abort(404);
}
return $dispatch;
});
\Route::post(\Request::path(), function () {
// Return a 404 when the alias is not found in the database
if (! $dispatch = $this->dispatchPostRoute()) {
\App::abort(404);
}
return $dispatch;
});
//\Route::get('test-searchpage', 'Komma\Search\SearchController@searchPages');
//job Routes
\Route::get('jobs/{jobId}', 'Komma\Jobs\JobController@show');
//Project Routes
\Route::get('projects', 'Komma\Projects\ProjectController@index');
\Route::get('projects/{projectId}', 'Komma\Projects\ProjectController@show');
//News Routes
\Route::get('news', 'Komma\Posts\PostController@index');
\Route::get('news/{newsId}', 'Komma\Posts\PostController@show');
\Route::get('newsletter/{newsId}', 'Komma\Posts\PostController@newsletter');
// Page Routes
\Route::resource('pages', 'Komma\Pages\PageController');
\Route::resource('references', 'Komma\References\ReferenceController');
\Route::any('photo_albums/{photoAlbumId}', 'Komma\PhotoAlbums\PhotoAlbumController@show');
// Forms
\Route::post('contact/process', [
'as' => 'contact.process',
'uses' => 'Komma\Contact\ContactController@contactFormProcess',
]);
\Route::get('contact', ['as' => 'contact.form',
'uses' => 'Komma\Contact\ContactController@contactForm',
]);
\Route::get('contact/succes', ['as' => 'contact.success',
'uses' => 'Komma\Contact\ContactController@contactSuccess',
]);
\Route::any('trial', [
'as' => 'trial.page',
'uses' => 'Komma\Contact\ContactController@freeTrialForm', ]);
\Route::post('trial/process', [
'as' => 'trial.process',
'uses' => 'Komma\Contact\ContactController@freeTrialProcess',
]);
\Route::get('trial/in-use', [
'as' => 'trial.in-use',
'uses' => 'Komma\Contact\ContactController@freeTrialSuccess',
]);
\Route::get('trial/succes', [
'as' => 'trial.success',
'uses' => 'Komma\Contact\ContactController@freeTrialSuccess',
]);
\Route::get('trial/error', [
'as' => 'trial.error',
'uses' => 'Komma\Contact\ContactController@freeTrialSuccess',
]);
\Route::post('setLanguage', 'BaseController@setCurrentLanguage');
// SEO routes
\Route::get('robots.txt', 'Komma\Sitemap\SitemapController@robots');
\Route::get('sitemap.xml', 'Komma\Sitemap\SitemapController@sitemap');
\Route::get('sitemap', 'Komma\Sitemap\SitemapController@showSitemap');
//404 route for maps in wwwroot
\Route::get('404', 'BaseController@abortPage');
}
/**
* Dispatch new custom event with REST-route
*
* @return mixed
*/
private function dispatchRoute()
{
$requestUri = \Request::path();
// Get route by URI
if (! $route = \DB::table('routes')
->where('route', '=', $requestUri)
->first()
) {
return false;
}
// Create get request
$request = \Request::create('/'.$route->rest_route, 'GET');
// dd($route);
// Dispatch request
return \Route::dispatch($request);
}
private function dispatchPostRoute()
{
$requestUri = \Request::path();
// Get route by URI
if (! $route = \DB::table('routes')
->where('route', '=', $requestUri)
->first()
) {
return false;
}
if (! (in_array($route->rest_route, ['contact', 'trial']) || starts_with($route->rest_route, 'photo_albums'))) {
return false;
}
// Create get request
$request = \Request::create('/'.$route->rest_route, 'POST');
// Dispatch request
return \Route::dispatch($request);
}
/**
* Check if the routes starts with "KMS"
*
* @return mixed
*/
private function isControlPanel()
{
return \Str::startsWith(\Request::path(), 'kms');
}
/**
* Check if the routes starts with "https"
*
* @return mixed
*/
private function redirectToHttps()
{
// Detect environment because it's only needed on production
if (\App::environment() == 'production') {
$tail = \Request::path();
// Check if request starts with main domain and https
if (! \Str::startsWith(\Request::root(), 'https://zuiderbos.nl')) {
// If not redirect to main domain with https
$redirect = 'https://zuiderbos.nl';
if ($tail != '/') {
$tail = '/'.$tail;
}
return \Redirect::to($redirect.$tail)->send();
}
}
}
private function checkOtherDomains()
{
if (str_contains(\Request::root(), 'fitaleadvies')) {
return \Redirect::to('http://fitale.nl')->send();
}
}
}