-1

So i've got the following code, but for some reason the use statement doesn't seem to do anything.

class Image {
    use \App\Traits\File;

    public static function get()
    {
         $image_url = File::getVersion()
    }
}

Throws an error Uncaught Error: Class 'File' not found. But it works if I change it to $image_url = \App\Traits\File::getVersion().

Does anyone know why?

KeironLowe
  • 711
  • 1
  • 8
  • 21

1 Answers1

0

Instead of that I would have created Traits directory in Http folder. Inside that I created file File. in class,

use App\Http\Traits\File;
class Image {
    use File;
    public static function get()
    {
         $image_url = File::getVersion()
    }
}

Above this should be the proper syntax to use namespace and trait.

Rahul
  • 18,271
  • 7
  • 41
  • 60