laravel 调用未定义的方法 Illuminate\View\View::make()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43452301/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Call to undefined method Illuminate\View\View::make()
提问by Nabeel Arbab
I am using Laravel 5.4.16 While using make method of View class i am getting undefined method error.
我正在使用 Laravel 5.4.16 在使用 View 类的 make 方法时,我收到未定义的方法错误。
public function Index()
{
return View::make('stats');
}
采纳答案by Alexey Mezenin
Try to add this to the top of the class:
尝试将此添加到类的顶部:
use View;
If it doesn't work then it looks like you didn't install the project. You need to run composer install
or composer update
command which will download and install all dependencies into the vendor
directory.
如果它不起作用,那么看起来您没有安装该项目。您需要运行composer install
或composer update
命令将所有依赖项下载并安装到vendor
目录中。
Another thing to check is config/app.php
should have this line:
要检查的另一件事是config/app.php
应该有这一行:
'View' => Illuminate\Support\Facades\View::class,
Alternatively, you could use helper:
或者,您可以使用助手:
return view('stats');
But it will work only if porject is installed properly.
但只有在正确安装项目的情况下它才能工作。
回答by prashant
return view('path.to.your.directory');
return view('path.to.your.directory');
回答by Tudor Corcimar
Just use Facade instead. Check how it works and then check what is wrong with View first. And I hope you are not using another template engine as Twig for example, cause if yes then you have definitely use Facade or check how the View factory is working, I think it requires template engine in the constructor ...
只需使用 Facade。检查它是如何工作的,然后首先检查 View 有什么问题。我希望你没有使用另一个模板引擎作为 Twig,因为如果是,那么你肯定使用了 Facade 或检查视图工厂是如何工作的,我认为它需要在构造函数中使用模板引擎......
Just use use Illuminate\Support\Facades\View;
只需使用 use Illuminate\Support\Facades\View;
回答by Muhammad Rizwan
You are receiving this error because make() method doesn't exist anywhere in your code. If you want to go from controller to view you can use simply:
您收到此错误是因为 make() 方法在您的代码中不存在。如果您想从控制器转到视图,您可以简单地使用:
public function Index() {
return view('stats');
}
It will go to your status blade view by accessing your url request.
它将通过访问您的 url 请求转到您的状态刀片视图。
回答by Vinicius Luiz
You can try to use it:
您可以尝试使用它:
return view('stats');