Profile picture upload method in Laravel 5.2 I am a Laravel newbie so please forgive me for my code... I have a method, in a Laravel controller, that updates the current logged user profile (postProfileGeneral()).
Logged user can upload a profile picture, and I manipulate the uploaded file (i.e. remove spaces, create unique name, etc.); since I'd like to reuse the upload routine, I put it on a separate method (_upload())
The code is this:

// get a unique file name
protected function _getUniqueFilename($path, $filename, $extension)
{
    $i = 2;
    $output = $filename . '.' . $extension;
    while(File::exists($path . '/' . $output)){
        $output = $filename . '_' . $i . '.' . $extension;
        $i++;
    }
    return $output;
}

// upload method, to reuse the routine
protected function _upload(Request $request, $field, $path = '')
{
    $path = ($path != '') ? $path : public_path();
    if ($request-&gt;hasFile($field)){
        $file = $request-&gt;file($field);
        if ($file-&gt;isValid()){
            $basename = $file-&gt;getClientOriginalName(); // get the original filename + extension
            $extension = $file-&gt;getClientOriginalExtension(); // get the original extension without the dot
            $filename = basename($basename, '.' . $extension); // get the original filename only
            $slug = str_slug($filename, '-'); // slug the original filename
            $name = $this-&gt;_getUniqueFilename($path, $slug, $extension);
            $file-&gt;move($path, $name);
            $output = $path . $name;
        }
    } else {
        $output = $request-&gt;input('cur_picture');
    }
    return $output;
}

// update profile
public function postProfileGeneral(Request $request)
{
    $picture = $this-&gt;_upload($request, 'picture', config('custom.users_path'));
    dd($picture);
    // rest of method here, not relevant
}


It works fine, but I feel there is a better way of doing this
My questions are:


since the getUniqueFilename() and _upload() method can be reused in other controllers too (i.e. for uploading products pictures, or whatever) where should I put them to be generally available?
in the getUniqueFilename() method I must pass Request object as a parameter: is there a better way to do this? At last, I yet have my Request object available in the postProfileGeneral() method...
I think your program is good. I repeat, IMO, it's good.
As you said in questions, the answers are


 Move your image manipulation related methods to a TRAIT. that'll help you while using the same code in different controllers. Because, if you want it to be done like this way, you must have to declare objects, if you want to use the same code from different controllers/classes. On the other hand, if you use TRAIT, you just have to use them. 


 As you're passing the Request to your method, you may pass the array instead. Otherwise, you may use check the file existence, on the previous method then pass the values to next method. You may wish to use varargs as a method parameter.