首先请温柔一点,我是初学者,我只是为了练习而编码。
我尝试将实例传递给模型,但总是收到此错误
Argument 1 passed to Store::__construct() must be an instance of Illuminate'Filesystem'Filesystem, none given
我的模型
<?php
use Illuminate'Filesystem'Filesystem as File;
class Store extends Eloquent
{
public $timestamps = false;
public function __construct(File $file)
{
$this->file = $file;
}
}
有人可以告诉我我做错了什么吗?
谢谢
编辑
我只是在我的控制器中简单地使用这样
public function index()
{
$store = new Store;
return View::make('store', $store);
}
File
类是 Laravels 立面之一,这意味着您不需要将其传递到模型构造中。
您可以使用 File::someMethod()
从 Laravel 的任何地方访问它。如果使用命名空间,则必须通过根命名空间'File::someMethod()
访问。
在您的store
视图中,您可以使用上述方法直接访问File
立面。
在此处查看有关文件系统的文档 http://laravel.com/api/class-Illuminate.Filesystem.Filesystem.html
因此,您可以使用File::copy()
,而不必实例化从静态方法调用的类。