public function upload($photo, $user_id, $album_id) { try { if (!Storage::disk('local')->exists($user_id)) { Storage::makeDirectory($user_id); } $destinationPath = public_path() . '/uploads/' . $user_id; $filename = str_random(10) . $photo->getClientOriginalName(); $upload_success = $photo->move($destinationPath, $filename); if ($upload_success) { $photo = new Photo(); $photo->name = $filename; $photo->user_id = $user_id; $photo->save(); $photo->albums()->attach($album_id); return array('status' => 1, 'photo' => $photo); } } catch (Exception $exp) { return array('status' => 0); } }