Laravel 5.1
我觉得很奇怪:
Route::group([
'middleware'=>['auth','acl:view activity dashboard'],
'prefix' => 'api/v1'
], function(){
Route::controller('investment-transactions', 'Api'V1'Investments'InvestmentTransactionsController');
Route::controller('investment-transactions/{offeringID}', 'Api'V1'Investments'InvestmentTransactionsController@getTransactionsForOffering');
});
对我来说很正常,控制器:
namespace App'Http'Controllers'Api'V1'Investments;
use App'Brewster'Models'Company;
use App'Http'Requests;
use App'Http'Controllers'Controller;
use Illuminate'Http'Request;
class InvestmentTransactionsController extends Controller {
public function __construct() {
}
public function getIndex() {
echo 'Here';
}
public function getTransactionsForOffering($offeringID) {
echo $offeringID;
}
}
动作和控制器退出,但是当我运行:php artisan routes:list
时,我得到:
[ReflectionException]
Class App'Http'Controllers'Api'V1'Investments'InvestmentTransactionsController@getTransactionsForOffering does not exist
显然App'Http'Controllers'Api'V1'Investments'InvestmentTransactionsController@getTransactionsForOffering
不是一个类,然而App'Http'Controllers'Api'V1'Investments'InvestmentTransactionsController
是,getTransactionsForOffering
是一个动作。
怎么回事?
我相信你的问题是在routes.php中,我们可以使用如下的控制器
Route::get('investment-transactions', 'InvestmentTransactionsController@index');
Route::get('investment-transactions/{offeringID}', 'InvestmentTransactionsController@getTransactionsForOffering');
默认情况下,我们的控制器存储在App/http/controllers文件夹中,laravel知道它。
我相信你只需要像这样引用这个类:
Route::controller('investment-transactions','InvestmentTransactionsController@Index'); //make sure you create a function for the index
Route::controller('investment-transactions/{offeringID}', 'InvestmentTransactionsController@getTransactionsForOffering');
假设您需要显示路由investment-transactions
的视图,在控制器中创建以下函数:
public function index()
{
return view('name-of-your-view-file');
}