简体   繁体   English

我必须在Laravel中使用什么命名空间或外观才能访问命名空间类中的模型?

[英]What namespace or facade do I have to use in Laravel to have access to my models inside a namespaced class?

I'm totally new to namespaces, and Laravel in general, so their use of Facades complicates the issue a bit for me. 我对名称空间和Laravel还是陌生的,所以对Facades的使用对我来说使问题变得有些复杂。

I have set up a class that is namespaced: 我已经建立了一个命名空间的类:

namespace Libraries;
class UploadedFile {
}

(As there is already a Symfony class uploadedFile), and now in that class I need to use one of my models, which I can only assume rests somewhere under the Eloquent facade, yet if I: (因为已经有一个Symfony类uploadFile),现在在该类中,我需要使用我的一个模型,我只能假设它位于Eloquent外观下的某个位置,但是如果我:

use Eloquent;

and

use \Eloquent;

in my class, I am told my model cannot be found, yet if I prepend my model with a backslash directly: 在我的课堂上,我被告知找不到我的模型,但是如果我在模型前面直接加一个反斜杠:

return \Object::create(...);

It works perfectly fine. 它工作得很好。 What do I need to use at the top of my namespaced file to include access to my models directly without the need for a slash? 我需要在命名空间文件顶部use什么以直接访问模型而不需要使用斜杠?

Eloquent has nothing to do with this. Eloquent与这无关。 You have to import your actual model Object : 您必须导入您的实际模型Object

use Object;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM