在Laravel 3中,可以使用Controller::Call方法调用控制器,如下所示:

Controller::call('api.items@index', $params);

I looked through the Controller class in L4 and found this method which seems to replace the older method: callAction(). Though it isn't a static method and I couldn't get it to work. Probably not the right way to do it?

我怎样才能在拉威尔4中做到这一点?

推荐答案

If I understand right, you are trying to build an API-centric application and want to access the API internally in your web application to avoid making an additional HTTP request (e.g. with cURL). Is that correct?

您可以执行以下操作:

$request = Request::create('api/items', 'GET', $params);
return Route::dispatch($request)->getContent();

Notice that, instead of specifying the controller@method destination, you'll need to use the uri route that you'd normally use to access the API externally.

Even better, you can now specify the HTTP verb the request should respond to.

Laravel相关问答推荐

Laravel:通过数据透视表数据限制多对多Eager 加载

如何在 Laravel 中使用多对一变形关系

使用正则表达式 laravel 忘记缓存

1 子编译中的警告(使用'stats.children:true'和'--stats-children'了解更多详细信息)

Laravel 在维护模式下显示自定义消息

Laravel Valet 安装后 Ping test.dev 返回未知主机

Laravel:如何强制使用 HTTPS?

Laravel:转义LIKE子句?

如何在 laravel 5.2 中显示 500 内部服务器错误页面?

.gitignore 不忽略文件夹

Laravel:`loadMissing` 函数的目的是什么?

Laravel - 排序的集合输出不是数组

Laravel 5 - 没有重叠的任务计划不起作用

如果值存在于另一个字段数组中,Laravel 验证规则

Laravel assets资源与混合

在 Laravel 5 控制器中找不到类App\Http\Controllers\DB

如何从 Laravel 中的资源中获取图像?

Laravel 5 Carbon 全局语言环境

日期时间格式无效:1366 字符串值不正确

开发中的 Laravel 和视图缓存 - 无法立即看到更改