N
N
nepster-web2016-04-25 16:33:40
Laravel
nepster-web, 2016-04-25 16:33:40

Laravel5. How to add an alias for only a certain part of the application?

I have a pseudo separation between backend and frontend, and there is a need to add an alias specifically for the backend.
Previously, I used middle ver to manipulate the configuration:

class Backend
{
    public function handle($request, Closure $next)
    {
        // Namespace для виджетов
        Config::set('laravel-widgets.default_namespace', 'App\Widgets\Backend');

        // Редирект после успешной аутентификации
        Config::set('auth.redirectAfterLogin', 'backend/auth');

        return $next($request);
    }
}

Everything works here. Now I needed to do a similar task for the backend with aliases in order to get the AuthHelper helper in all types.
I tried doing something like:
Config::set('app.aliases', array_merge(Config::get('app.aliases'), [
            'AuthHelper' => \App\Helpers\Backend\AuthHelper::class,
        ]));
      
       или

        \App::alias('AuthHelper', \App\Helpers\Backend\AuthHelper::class);

The result is the same: Class 'AuthHelper' not found
Moreover, if you simply add to the config:
'aliases' => [
        ...
        'AuthHelper'  => \App\Helpers\Backend\AuthHelper::class,
        ...
    ],

Everything will work. But the problem is that I need different AuthHelpers for the backend part and the frontend part.
How can this matter be resolved?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nepster-web, 2016-04-25
@nepster-web

Googled:
'

// Перерегистрация класса AuthHelper
        $loader = \Illuminate\Foundation\AliasLoader::getInstance();
        $loader->alias('AuthHelper', \App\Helpers\Backend\AuthHelper::class);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question