在 Laravel 4 中直接访问停止方法

Stop method being accessed directly in Laravel 4

我有一个方法,例如 UserController@getRead 来读取所有或特定用户的详细信息。我有一条路线 Route::controller('user', 'UserController'); 以便在任何其他方法中我可以使用以下方法获取有关用户的信息:

$request = Request::create('user/read/'.$userId, 'GET');
$user = json_decode(Route::dispatch($request)->getContent());

但这也意味着我可以浏览到 'user/read/1' 并获取用户 1 的所有信息。这显然是一个安全漏洞,需要修复。如何在应用程序中访问 UserController 的读取方法,而不是直接通过浏览 user/read?

可以用Request::path()获取浏览器输入的路径,然后测试是否为user/read。如果中止,则继续。这是我针对特定实例的代码:

if (stripos(Request::path(), 'user/read') !== false)
{
    App::abort(403, 'No direct access allowed');
}