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
并且public class Page2ViewModel: Screen
{
protected override void OnActivate()
{
base.OnActivate();
}
protected override void OnDeactivate(bool close)
{
base.OnDeactivate(close);
}
}
是一个动作。
怎么回事?
答案 0 :(得分:0)
我相信你只需像这样引用这个类:
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');
}
答案 1 :(得分:0)
我相信你的问题在routes.php我们可以使用控制器如下
Route :: get('investment-transactions','InvestmentTransactionsController @ index');
Route :: get('investment-transactions / {offeringID}','InvestmentTransactionsController @ getTransactionsForOffering');
默认情况下,我们的控制器存储在 App / http / controllers 文件夹中,laravel知道它。