File: D:/HostingSpaces/SBogers85/dale-int.com/app/Komma/Routes/RouteResolver.php
<?php
namespace Komma\Routes;
use Illuminate\Support\Facades\Redirect;
class RouteResolver
{
/**
* Resolve route
*
* @return bool
*/
public function resolve()
{
// Return false when we are in the control panel
if ($this->isControlPanel()) return false;
// 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;
});
//Project Routes
\Route::get('projects', 'Komma\Projects\ProjectController@index');
\Route::get('projects/{projectId}', 'Komma\Projects\ProjectController@show');
//Post Routes
\Route::get('blog', 'Komma\Posts\PostController@index');
\Route::get('blog/{blogId}', 'Komma\Posts\PostController@show');
//News Routes
\Route::get('news', 'Komma\Posts\PostController@index');
\Route::get('news/{newsId}', 'Komma\Posts\PostController@show');
// Vacancies Route
\Route::get('/vacatures', function (){
return \View::make('layouts.pages.vacancies');
});
\Route::get('/vacancies', function (){
return \View::make('layouts.pages.vacancies');
});
\Route::get('/karriere', function (){
return \View::make('layouts.pages.vacancies');
});
\Route::get('/', function (){
return Redirect::to('/nl');
});
// Page Routes
\Route::resource('pages', 'Komma\Pages\PageController');
// 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::post('setLanguage', 'BaseController@setCurrentLanguage');
// SEO routes
\Route::get('robots.txt', 'Komma\Seo\SEOController@robots');
\Route::get('sitemap.xml', 'Komma\Seo\SEOController@sitemap');
//404 route for maps in wwwroot
\Route::get('404', 'BaseController@abortPage');
/*//Disclaimer
\Route::get('/disclaimer', function()
{
\View::make('layouts.pages.disclaimer');
});*/
}
/**
* Dispatch new custom event with REST-route
*
* @return mixed
*/
private function dispatchRoute()
{
$root = \Request::root();
if(str_contains($root, 'dale-int.nl')) return \Redirect::to('http://dale-int.com/nl', 301);
if(str_contains($root, 'dale-int.de')) return \Redirect::to('http://dale-int.com/de', 301);
if(str_contains($root, 'dale-int.be')) return \Redirect::to('http://dale-int.com/nl', 301);
if(str_contains($root, 'dale-int.co.uk')) return \Redirect::to('http://dale-int.com', 301);
if(str_contains($root, 'dale-int.eu')) return \Redirect::to('http://dale-int.com', 301);
// URI
$requestUri = \Request::path();
switch($requestUri){
case 'nl':
case 'be':
$languageSetter = new \Komma\LanguageService();
$languageSetter->setCurrentLanguage('nl');
break;
case 'de':
$languageSetter = new \Komma\LanguageService();
$languageSetter->setCurrentLanguage('de');
break;
default:
$languageSetter = new \Komma\LanguageService();
$languageSetter->setCurrentLanguage('en');
break;
};
// 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');
// Dispatch request
return \Route::dispatch($request);
}
private function dispatchPostRoute(){
// URI
$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'])) 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');
}
}