barryvdh / laravel-elfinder

elFinder bundle for Laravel
738 stars 171 forks source link

Override Config #62

Open elite123 opened 9 years ago

elite123 commented 9 years ago

I am trying to set a root to the currently logged in user:

/files/1/ - user 1's files /files/2/ - user 2's files

Therefore I tried to override the config in ElfinderController:

\Config::set('elfinder.roots.user.path', public_path().'/uploads/user/'.\Auth::user()->id);
\Config::set('elfinder.roots.user.URL', '/uploads/user/'.\Auth::user()->id.'/');
\Config::set('elfinder.roots.user.alias', \Auth::user()->name);

However, these config values never get used - is there anyway to get this working or am I taking the wrong approach?

anndro commented 9 years ago

I was looking to how to fix same problem. Maybe its not good way but I find a solution.

I added this bottom of the routes.php Now It works.

use Senrty;
if(Sentry::check())
{
   \Config::set('elfinder.roots.0.path', Sentry::getUser()->userid);
   \Config::set('elfinder.roots.0.alias', Sentry::getUser()->username);
}
anndro commented 9 years ago

Found better way at L5. Create a middleware.

public function handle($request, Closure $next)
{
    if(Sentry::check())
    {
        \Config::set('elfinder.roots.0.path', Sentry::getUser()->userid);
        \Config::set('elfinder.roots.0.alias', Sentry::getUser()->username);
    }
    return $next($request);
}

Then set middleware at config.

'route' => [
    'prefix' => 'elfinder',
    'middleware' => 'App\Http\Middleware\FileBrowser', 
],
Unoffe commented 5 years ago

Can I ask how can I do same thing without Sentry::class?