laravel UnexpectedValueException in Route.php line 639: Invalid route action: [App\Http\Controllers\PortfolioController]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33182331/
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
UnexpectedValueException in Route.php line 639: Invalid route action: [App\Http\Controllers\PortfolioController]
提问by Tbaustin
Why am I getting this error. I created a PortfolioController. Then I made a route using this
为什么我会收到此错误。我创建了一个 PortfolioController。然后我用这个做了一条路线
Route::get('portfolio','PortfolioController');
So in my controller page I made this.
所以在我的控制器页面中我做了这个。
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class PortfolioController extends Controller
{
//This only gets exectued when we request /portfolio/Paintings using GET
public function getPaintings()
{
return 'This RESTful controller is working!';
}
}
I get this error when typing in localhost/portfolio/paintings
输入 localhost/portfolio/paintings 时出现此错误
回答by patricus
From the look of your code, it looks like you're trying to setup an implicit controller route. You're close, but your route definition is a little off. You need to use controller
instead of get
:
从您的代码来看,您似乎正在尝试设置一个隐式控制器 route。你很接近,但你的路线定义有点偏离。您需要使用controller
代替get
:
Route::controller('portfolio','PortfolioController');
回答by Tiago Gouvêa
https://laravel.com/docs/5.3/upgrade#upgrade-5.3.0
https://laravel.com/docs/5.3/upgrade#upgrade-5.3.0
The following features are deprecated in 5.2 and will be removed in the 5.3 release in June 2016:
- Implicit controller routes using
Route::controller
have been deprecated. Please use explicit route registration in your routes file. This will likely be extracted into a package.
以下功能在 5.2 中已弃用,并将在 2016 年 6 月的 5.3 版本中删除:
Route::controller
不推荐使用隐式控制器路由。请在您的路由文件中使用显式路由注册。这很可能会被提取到一个包中。
You must declare each endpoint now.
您现在必须声明每个端点。
回答by Alan-Wen
I got a similar error when there was a mistake in he file of web.php.
当 web.php 文件中出现错误时,我遇到了类似的错误。
A correct route would like this Route::get('portfolio','YourController@yourMethod');
正确的路线是这样的 Route::get('portfolio','YourController@yourMethod');
回答by Edward
You have to consume a function of the controller instead of using the whole controller class for one request. so laravel doesn't know which of your function to use.
您必须使用控制器的一个函数,而不是为一个请求使用整个控制器类。所以 laravel 不知道要使用哪个函数。
Try using PortfolioController@index
. or Route::resource('yourroute','PortfolioController');
尝试使用PortfolioController@index
. 或者Route::resource('yourroute','PortfolioController');
回答by Chandni Soni
Try this: Route::resource('/portfolio','PortfolioController'); Hope this will work
试试这个: Route::resource('/portfolio','PortfolioController'); 希望这会奏效
回答by kamran geE
try this
尝试这个
Route::get('portfolio','PortfolioController@getPaintings')
Route::get('portfolio','PortfolioController@getPaintings')
回答by Aman Kumar
Use this code in routes:
在路由中使用此代码:
Route::resource('portfolio','YourController@yourMethod');
回答by Ryuujo
you need to explain your function on Route. example:
您需要在 Route 上解释您的功能。例子:
Route::methods('your-uri','YourController@YourFunction');
so you should do this:
所以你应该这样做:
Route::get('portfolio','PortfolioController@getPaintings');
Hope it helps
希望能帮助到你