dimanche 3 juillet 2016

Displaying of month and it's year based on condition

In my Laravel 5.1 application, I have a feature of Subscription. It is working to a certain extent, but not what I am looking for..

Scenario: A user makes a subscription on October 2016 for 6 months.. So, the array will look something like this:

[
    "subscription_months" => 6
    "subscription_start_month" => "01-10-2016" // <-- will be carbon instance
    "subscription_end_month => "31-03-2017" // <-- will be carbon instance
    "monthName" => "October"
]

The above array I am showing is only 1 month.. There will be 5 more elements in the array..

What I want is, I want to append the Year after monthName

So, it would look something like this.

[
    [
        "monthName" => "October, 2016" // <-- for 1st month
    ]

    [
        "monthName" => "November, 2016" // <-- for 2nd month
    ]

    [
        "monthName" => "December, 2016" // <-- for 3rd month
    ]

    [
        "monthName" => "January, 2017" // <-- for 4th month
    ]

    [
        "monthName" => "February, 2017" // <-- for 5th month
    ]

    [
        "monthName" => "March, 2017" // <-- for 6th month
    ]
]

The code that I have tried so far is:

$startMonthForMixed = $invoice->subscription_start_date->month;

for($i = 0; $i < $invoice->subscription_months; $i++) {
    $convertedInvoices[] = [
        'id' => $invoice->id,
        'order_code'               => $invoice->order_code,
        'order_type'               => 'Mixed - Subscription',
        'subscription_months'      => $invoice->subscription_months,
        'subscription_start_month' => $invoice->subscription_start_date,
        'subscription_end_month'   => $invoice->subscription_end_date,
        'monthName'                => date("F", mktime(0, 0, 0, $startMonthForMixed, 01)) . ", " . Carbon::now()->addYear()
     ];
     $startMonthForMixed++;
 }

Can anybody help out with this ? Thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire