1
votes

My folder structure looks like below

app
    Console
    Events
    Exceptions
    Http
        Classroom
            Controllers
            Middleware
            Requests
            Kernel.php
        Default
            Controllers
            Middleware
            Requests
            Kernel.php
        Homework
            Controllers
            Middleware
            Requests
            Kernel.php
        routes-classroom.php
        routes-default.php
        routes-homework.php
        routes.php
    Jobs
    Listeners
    Policies
    Providers
    User.php
bootstrap
config
database
public
public_classroom
    bootstrap
        cache
        app.php
        autoload.php
public_homework
    bootstrap
        cache
        app.php
        autoload.php
resources
storage
tests
vendor

My vhsot is like:

cr.classroom.loc => public_classroom
hw.classroom.loc => public_homewrok

I want when cr.classroom.loc is accessed then Http/Classroom/controller will be accessed and same will happen for hw.classroom.loc as well. I have fixed the namespaces accordingly ran composer dump-autoload, php artisan clear-compiled but nothing helps. The follwing error is displayed:

Uncaught exception 'ReflectionException' with message 'Class log does not exist' in /var/www/classroom/vendor/laravel/framework/src/Illuminate/Container/Container.php:741

1
this is just a preliminary message as the server is unable to write to log files. Change permissions to 777 for storage folder and then try again to get the real error message.Vikas
@Vikas storage folder's permission is 777 from the beginningMd. Nurul Islam

1 Answers

0
votes

The problem was in Route Service Provider. Provider was not being able to resolve the requests. Added the following code to the provider.

protected $ar_subdomain_namespaces = [
    '' => 'Home',
    'cr' => 'Classroom',
    'hw' => 'Homework',
    'lms' => 'Lms',
    'admin' => 'Admin',
    ...
];

public function map(Router $router) {
    $this->mapWebRoutes($router);
}

protected function mapWebRoutes(Router $router) {
    if (isset($_SERVER['HTTP_HOST'])) {
        $fqdn = $_SERVER['HTTP_HOST'];
        $ar_host = explode(".", $fqdn);
    }

    $sub_domain = ( isset($ar_host) && count($ar_host) > 2 && $ar_host[0] !== 'www' ) ? $ar_host[0] : '';
    list($namespace, $route_path) = $this->getNamepaceAndRouteBySubdomain($sub_domain);

    $router->route_file_path = $route_path;
    $router->group([
        'namespace' => $namespace, 'middleware' => 'web',
            ], function ($router) {
        require app_path($router->route_file_path);
    });
}

protected function getNamepaceAndRouteBySubdomain($sub_domain = '') {
    $namespace = '\Controllers';
    $route_path = 'Http/Home/routes.php';

    if (array_key_exists($sub_domain, $this->ar_subdomain_namespaces)) {
        $route_path = "Http/{$this->ar_subdomain_namespaces[$sub_domain]}/routes.php";
        $namespace = "{$this->namespace}\\{$this->ar_subdomain_namespaces[$sub_domain]}{$namespace}";
    }

    return [$namespace, $route_path];
}