HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers96/smilefotografie.nl/app/Komma/Routes/RouteResolver.php
<?php

namespace Komma\Routes;


class RouteResolver
{
    /**
     * Resolve route
     *
     * @return bool
     */
    public function resolve()
    {
        // Check if we are on an old route
        $this->redirectOldPages();

        // Return false when we are in the control panel
        if($this->isControlPanel()) return false;

        // Forms
        \Route::post('form/offer/process',[
            'as'    =>  'form.offer.process',
            'uses'  =>  'Komma\Forms\FormController@process'
        ]);

        // If route above not found, 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;
        });

        // Page Routes
        \Route::get('pages/{pageId}','Komma\Pages\PageController@show');
        \Route::get('pages/{pageId}/albums/{albumId}','Komma\Albums\AlbumController@show');

        // SEO routes
        \Route::get('robots.txt', 'Komma\Seo\SEOController@robots');
        \Route::get('sitemap.xml','Komma\Seo\SEOController@sitemap');

    }

    /**
     * Dispatch new custom event with REST-route
     *
     * @return mixed
     */
    private function dispatchRoute()
    {
        // URI
        $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');

        // Dispatch request
        return \Route::dispatch($request);
    }

    /**
     * Check if the routes starts with "KMS"
     *
     * @return mixed
     */
    private function isControlPanel()
    {
        return \Str::startsWith(\Request::path(),'kms');
    }

    /**
     * Redirect old links to the new pages
     */
    private function redirectOldPages()
    {
        $location = false;

        // Get path with query string
        switch(\Request::path())
        {
            case 'category':
                if(\Str::contains(\Request::getQueryString(),'Companies'))
                    $location = 'zakelijk';

                if(\Str::contains(\Request::getQueryString(),'Private'))
                    $location = 'particulier';

                if(\Str::contains(\Request::getQueryString(),'Travel') ||
                   \Str::contains(\Request::getQueryString(),'Cars') )
                    $location = 'vrij-werk';
                break;
        }

        if($location !== false)
        {
            header("HTTP/1.1 301 Moved Permanently");
            header("Location: /" . $location);
            exit;
        }
    }
}