Search code examples
phplaravel-5laravel-filesystem

Laravel file manager Dynamic base_directory


I using unisharp's laravel file manager. it works great and i am in love with the flexibility it has.

However, I need to users to store their files in their respective folders. i am able to do this by changing user_field in conf file. What i am not able to do is give acess to super administrator so that he can see all other user's files! i am almost giving up trying to figure this for days.

here is what i have tried so far:

in config/lfm.php

'base_directory'=>Unisharp\Laravelfilemanager\Handlers\ConfigHandler::class`,

And in the handler:

namespace Unisharp\Laravelfilemanager\Handlers;
class ConfigHandler
{
    public function userField()
    {
        return auth()->user()->name;
    }

    public function baseDirectory(){
        if(auth()->user()->user_type !== "S"){
            return 'storage/'.auth()->user()->name;
        }
        else{
            return 'storage/';
        }
    }
}

But the above code shows a blank page and it creates folders in Abyss which i cant find anywhere on my machine.

Any help will be appriciated.

Thanks in advance.


Solution

  • I had the same problem. I managed to fix it modifying the function userField itself:

    public function userField()
    {
        $role = function_to_get_role();
    
        if($role == 'Admin'){
            return 'folder_1';
        }else{
            return 'folder_1/' . auth()->user()->name;          
        }
    }
    

    I tried to modify baseDirectory function too but had no success.