Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何解决Laravel(IoC容器)中的BadMethodCallExection_Php_Laravel_Namespaces_Ioc Container - Fatal编程技术网

Php 如何解决Laravel(IoC容器)中的BadMethodCallExection

Php 如何解决Laravel(IoC容器)中的BadMethodCallExection,php,laravel,namespaces,ioc-container,Php,Laravel,Namespaces,Ioc Container,当我添加Route::resource('api','ApiController')到我的app/Http/routes.php,我得到以下错误: BadMethodCallException方法[index]不存在 我的api控制器如下所示: <?php class ApiController extends BaseController { public function getIndex() { ech

当我添加
Route::resource('api','ApiController')
到我的app/Http/routes.php,我得到以下错误:

BadMethodCallException方法[index]不存在

我的api控制器如下所示:

<?php

    class ApiController extends BaseController
    {     
        public function getIndex()
        {
           echo "No Access";
        }
        public function postIndex()
        {
            // content here ...
        }
        public function check_ban($user, $gameBit, $ip)
        {
            // content here ...
        }
        public function check_balance($userid, $gameid, $serverid)
        {
            // content here ...
        }
        public function purchase_item($xml)
        {
            // content here ...
        }
        public function LoginRequest($xml)
        {
            // content here ...
        }
        public function CurrencyRequest($xml)
        {
            // content here ...
        }
        public function ItemPurchaseRequest($xml)
        {
            // content here ...
        }
    }

当您使用以下命令声明资源丰富的路由时

Route::resource('api', 'ApiController');
然后让
Laravel
为您生成方法,因此转到
命令提示符/terminal
并运行:

php artisan controller:make ApiController
这将在
app/controllers
目录中创建一个
ApiController
resourceful控制器,并将创建所有方法(方法的框架)。要确保哪个方法侦听哪个
URI
HTTP
方法,请从
命令提示符/terminal
运行
php artisan routes
,这样您就知道了。请在
Laravel
网站上阅读更多信息

如果要针对
HTTP
谓词声明自己的方法,请创建
RESTful
控制器,并且要创建
RESTful
控制器,您不必从
终端运行任何
artisan
命令,而是使用以下命令声明路由:

Route::controller('api', 'ApiController');
然后创建前缀为
HTTP
动词的方法,以响应该动词,例如:

class ApiController extends BaseController {

    // URL: domain.com/api using GET HTTP method
    public function getIndex()
    {
        //...
    }

    // URL: domain.com/api/profile using POST HTTP method
    public function postProfile()
    {
        //...
    }

    // ...
}
如果您运行
php artisan routes
,那么您将能够看到所有
URI
s和方法映射。查看
Laravel
网站