【问题标题】:Class does not exist for laravel routeslaravel 路由不存在类
【发布时间】:2015-12-22 07:13:32
【问题描述】:

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 是一个动作。

发生了什么事?

【问题讨论】:

  • 试试Route::controller('investment-transactions', 'InvestmentTransactionsController@Index'); Route::controller('investment-transactions/{offeringID}', 'InvestmentTransactionsController@getTransactionsForOffering');
  • 你的自定义控制器的路径是什么?

标签: php routing laravel-routing laravel-5.1


【解决方案1】:

我相信你只需要像这样引用类:

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');
}

【讨论】:

  • 当我这样做时,我得到:Class App\Http\Controllers\Api\V1\Investments\InvestmentTransactionsController@Index does not exist 当我尝试 @getIndex 时,它的错误相同,但 @getIndex@aqq
  • 你的控制器的路径是什么?
【解决方案2】:

我相信你的问题是在 routes.php 我们可以使用控制器如下

Route::get('investment-transactions', 'InvestmentTransactionsController@index');
Route::get('investment-transactions/{offeringID}', 'InvestmentTransactionsController@getTransactionsForOffering');

默认情况下,我们的控制器存储在 App/http/controllers 文件夹中,laravel 知道。

【讨论】:

    猜你喜欢
    • 2020-11-16
    • 2015-03-01
    • 2019-11-26
    • 2015-11-09
    • 2020-11-08
    • 2019-07-27
    • 2016-06-07
    • 2015-06-01
    • 2015-11-23
    相关资源
    最近更新 更多