0

I find function for user registeration:

public function postRegister(Request $request)
    {
        $validator = $this->validator($request->all());

        if ($validator->fails()) {
            $this->throwValidationException(
                $request, $validator
            );
        }

        Auth::login($this->create($request->all()));
    File::makeDirectory('/images/'.Auth::user()->id);

        return redirect($this->redirectPath());
    }

but is possible to create folder inisde image folder with name $user->id so to create folder like /images/1

I try with

$result = File::makeDirectory('/images/'.Auth::user()->id);

but without success

I also try :

$directory = public_path().'\images'.Auth::user()->id;
File::makeDirectory($directory);

but again I just dont see folder ...

Is there any way to create folder inside public/images/user->id on user register

2 Answers 2

2

Set recursive to true as a third argument try this:

File::makeDirectory(public_path().'/images/'.Auth::user()->id, 0755, true);

Sign up to request clarification or add additional context in comments.

3 Comments

Have you any idea what if user not logged in and i want to create user_id directory which is created??
can you explain more what do you want exactly to achieve
I've done it! Thanks for your reply. I just want to create directory when user register with their id and when user register he's not logged in so auth id not valid! But now get it with user->id when register. thanks for your reply!
1

Make sure to use the File facade within laravel, you could do the following:

use File;
File::makeDirectory(base_path("/images/".Auth::user()->id), 0755, $recursive = true, $force = false);

or:

use File;
File::makeDirectory(base_path("/images/".Auth::user()->id), 0755, true);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.