Search code examples
laravelstripe-paymentslaravel-cashier

How to update ends_at field of laravel cashier


I want to update ends_at column of subscriptions table. When i use

Carbon::now()

It update perfectly but when is use

Carbon::now()->addCenturies(5);

I am face error

SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2520-08-07 11:39:13' for column 'ends_at' at row 1 (SQL: update `subscriptions` set `ends_at` = 2520-08-07 11:39:13, `subscriptions`.`updated_at` = 2020-08-07 11:39:13 where `id` = 1)

i want one subscription for life time due to this i think add centuries. kinldy tell me solution my controller code is

  $subscription = $user->newSubscription('default', $plan->plan_id)->create($request->paymentMethod, [ 'email' => $user->email ]); 
                $subscription->ends_at = Carbon::now()->addCenturies(5);
                $subscription->save();

Solution

  • The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of 1970-01-01 00:00:01 UTC to 2038-01-19 03:14:07 UTC. Your given year is 2520 and your MySQL can handle year as max 2038.
    Change the migration timestamp to dataTime format as :

    $table->timestamp('ends_at');
    

    to

    $table->dateTime('ends_at');