samedi 17 octobre 2015

Laravel 5 File Facade not execute next code if statement false

with this code if file exist it will give me error

ErrorException in Filesystem.php line 338: mkdir(): File exists

instead of execute next code which will insert user table

.....
if(!File::exists($path.$data['avatar']->getClientOriginalName())){
    File::makeDirectory($path, 0755, true);
    Image::make($data['avatar']->getRealPath())->resize(200, 200)->save($path.$data['avatar']->getClientOriginalName());
    Post::create([
            'user_id' => Auth::user()->id,
            'content' => "assets/uploads".date('/Y/m/d/').$data['avatar']->getClientOriginalName(),
            'type'    => 'image'
        ]);
}
$user = new User;
$user->username = $data['username'];
$user->password = Hash::make($data['password']);
$user->avatar   = "assets/uploads".date('/Y/m/d/').$data['avatar']->getClientOriginalName();
$user->email = $data['email'];
$user->first_name = $data['first_name'];
$user->last_name = $data['last_name'];
$user->role_id = $data['level'];
$user->save();
....

AFAIK the above code should execute insert if statement true or false, should i use else statement? if so then I must repeat insert user twice and it's bad.

So, the question is why the above code return error instead of execute next code? and how to fix it?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1OAqNOr
via IFTTT

Aucun commentaire:

Enregistrer un commentaire