panthro
panthro

Reputation: 24069

Aliasing in Laravel not working?

I wish to call my model (file.php). At the top of my namespaced class I use:

use \file as mFile;
use \File;

I then can do stuff like:

mFile::orderBy('name')->paginate(10);

But if I use the laravel File class before I use the model:

File::get($test->getRealPath())
mFile::orderBy('name')->paginate(10);

The model fails to work, as it tries to access this instead of the model:

Illuminate\Filesystem\Filesystem

Why is it doing this?

Upvotes: 1

Views: 117

Answers (1)

DouglasDC3
DouglasDC3

Reputation: 495

To php \File and \file is the same class. PHP classes are case-insensitive.

I suggest you namespace your model like Acme\File to avoid this problem. It is also convention to have all classes by camel cased.

Hope this helps

Upvotes: 2

Related Questions