I am using elfinder laravel package to manage and organize files.
It has a elfinder.dir
config options that used to specifies a directory that user can upload files to it.
Now I want to change (or create) this option to a directory same name as logged in User username
.
For that I wrote some codes in a middleware that runs after user authentication for limit access of user to admin panels. like this :
class IsAdmin
{
public function handle ($request, Closure $next)
{
if (Auth::check()) {
$username = Auth::user()->username;
if (!File::exists(public_path('upload') . '/' . $username)) {
File::makeDirectory(public_path('upload') . '/' . $username, 0775);
}
Config::set('elfinder.dir', ["upload/$username"]);
return $next($request);
}
return Redirect::to('/admin/login');
}
}
As you can see if there no directory same as username it will be create.
But I want to know it is right that I do this operations in a middleware or there are another(or proper) place to that ?