lundi 4 septembre 2017

different path for different user

The concept is really simple to me, but having a behaviour like that in Laravel 5.4 start to be a likkle bit tricky to me! Can any one help me to understand better what im doing!!!

The concept is to have different folder on local disk for different users. So in the "register" function ive added this code: $username=$data['name']; if (! preg_match('/\s/', $username) ){

        Storage::makeDirectory("users/".$username."_".$user->id);

    }else{

        $username= preg_replace('/\s+/','', $username);
        Storage::makeDirectory("users/".$username."_".$user->id);

    }

This code check if the name contains spaces, strip from them and create a folder on the local disk at user's registration [IT WORKS]

then on a function that my user using I need to retrieve this path and using for saving his own file, so I add:

username=Auth::user()->name;
        if ( preg_match('/\s/', $username) ){
            $username= preg_replace('/\s+/','', $username);
        }
        if(! Storage::disk('local')->has("users/".$username."_".Auth::user()->id)){
            Storage::makeDirectory("users/".$username."_".Auth::user()->id);
        }

I check again if the folder exist (otherwise i'll do it) and then I'd like to use it in the next instruction for saving the file contained in my request, using "Storage::"

How can I specify the folder path?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire