在我的一个中间件中,我使用了类似这样的东西
$user = [
'name' => 'noob',
'phone' => '87548154'
]; /* which actually comes from redis cache */
$request->attributes->set('user', $user);
在控制器中我像使用它一样
$request->get('user')['name']
或者
$request->get('user')['phone']
由于这看起来非常灵活,我想将更多数据附加到 $user 数组中。在 laravel 文档中,它上面写的 Request 类的 get() 方法是
* Gets a "parameter" value from any bag.
* This method is mainly useful for libraries that want to provide some flexibility. If you don't need the
* flexibility in controllers, it is better to explicitly get request parameters from the appropriate
* public property instead (attributes, query, request).
* Order of precedence: PATH (routing placeholders or custom attributes), GET, BODY
我的问题是,这会是个好主意吗?因为最常用的数据已经附加在中间件中。这样我就不必一次又一次地在控制器方法中编写额外的代码。它会影响高流量服务器的性能吗?