【发布时间】:2013-08-22 10:56:21
【问题描述】:
我有一个应用程序在循环中运行类似SomeModel::getValue($month, $year, $departmentId) 的函数。
getValue 创建查询并返回结果:
return self::where('department_id', '=', $department_id)
->where('year', '=', $year)
->where('month', '=', $month)
->pluck('value');
在这个循环中,它可能会多次调用相同的参数。 我想知道每次我想获取数据时避免创建新查询的最佳方法。
我考虑在模型中创建一个静态数组,并在每次调用 getValue 时对其进行匹配。如果数组中存在值,则返回它,如果不存在则创建查询。
我的解决方案好吗?你有什么其他想法吗?谢谢!
我正在使用 Laravel 4
【问题讨论】:
标签: php mysql laravel laravel-4 eloquent