从laravel 5中的查询中获取月份名称

时间:2016-12-07 12:31:44

标签: mysql laravel-5

我正在尝试显示查询中的月份名称但不打印。

以下是我的询问:

$stats = DB::table('leadsheet')
            ->whereYear('created_at', '>=', $days)
            ->groupBy('month')
            ->orderBy('month', 'ASC')
            ->get([
                DB::raw('MONTH(created_at) as month'),
                DB::raw('COUNT(*) as value')
            ]); 

我的json数据如下:

[{"month":1,"value":380},{"month":2,"value":2146},{"month":3,"value":2008},{"month":4,"value":1399},{"month":5,"value":1719},{"month":6,"value":4497},{"month":7,"value":911},{"month":8,"value":495},{"month":9,"value":691},{"month":10,"value":370},{"month":11,"value":479}]

在这个结果中,我只想显示数字1为Jan,2显示为2月等等。但是我试图给出月份格式没有发生。

期望的输入如:

{"month":Jan,"value":380}...

有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:2)

您可以使用@RunWith(SpringJUnit4ClassRunner.class) @TestExecutionListeners({DependencyInjectionTestExecutionListener.class, StepScopeTestExecutionListener.class}) @ContextConfiguration(loader = SpringApplicationContextLoader.class, classes = ItemReturnsApplication.class) public class StepIntegrationTest { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; @Test public void testLaunchJob() throws Exception{ JobExecution jobExecution = jobLauncherTestUtils.launchStep("nameOfYourStep"); } }

CASE EXPRESSION

或者,您可以使用MONTHNAME()