我在Laravel中构建了一个API,其版本如下:
/controllers/api/v1/CommentController.php
/controllers/api/v2/CommentController.php
在我的路线中,我会像这样调用正确的控制器:
Route::resource('notification', 'api\v2\CommentController');
这样可行,但由于我在控制器中使用命名空间,我必须使用\方法才能在根命名空间中找到类似\ Response的类?
namespace api\v1;
class NotificationController extends \BaseController {
public function index()()
{
return \Response::json({});
}
}
有没有办法避免使用反斜杠表示法并使用正确的命名空间?
我尝试使用use \App;
但没有结果
答案 0 :(得分:1)
你需要添加"使用Response;"你的代码。
<?php namespace api\v1;
use Response;
class CommentController extends \BaseController {
public function index()
{
return Response::json('hello');
}
}