bpuig / laravel-subby

Laravel Plan and Subscriptions manager.
https://bpuig.github.io/laravel-subby
MIT License
102 stars 42 forks source link

Method addMounths does not exist ---> newSubscription() #143

Closed mohamedben82 closed 1 year ago

mohamedben82 commented 1 year ago

Hello I'm facing this error when i try to use newSubscription() for a client model image

Here's my code

$client=Client::find(2);
        $plan = Plan::find(1);
        //  dd($client); 
        //  dd($plan);
        $client->newSubscription(
            'main', // identifier tag of the subscription. If your application offers a single subscription, you might call this 'main' or 'primary'
             $plan, // Plan or PlanCombination instance your subscriber is subscribing to
             'Main subscription', // Human-readable name for your subscription
             'Customer main subscription', // Description
             null, // Start date for the subscription, defaults to now()
             'free' // Payment method service defined in config
             );

dd($client);

App\Models\Client {#1480 ▼ // app\Http\Controllers\TestController.php:14
  #connection: "mysql"
  #table: "clients"
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  +preventsLazyLoading: false
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #escapeWhenCastingToString: false
  #attributes: array:6 [▼
    "id" => 2
    "name" => "Tarik test"
    "email" => "tarik@something.ma"
    "phone" => "23424234"
    "created_at" => "2022-11-04 22:46:34"
    "updated_at" => "2022-11-04 22:46:34"
  ]
  #original: array:6 [▶]
  #changes: []
  #casts: []
  #classCastCache: []
  #attributeCastCache: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #fillable: array:3 [▶]
  #guarded: array:1 [▶]
}

dd($plan) :

Bpuig\Subby\Models\Plan {#1496 ▼ // app\Http\Controllers\TestController.php:15
  #connection: "mysql"
  #table: "plans"
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  +preventsLazyLoading: false
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #escapeWhenCastingToString: false
  #attributes: array:19 [▼
    "id" => 1
    "tag" => "basichebergement"
    "name" => "Hébergement Basic"
    "description" => "description pour l'hebergement basic"
    "is_active" => 1
    "price" => "150.00"
    "signup_fee" => "20.00"
    "currency" => "DH"
    "trial_period" => 0
    "trial_interval" => "day"
    "trial_mode" => "outside"
    "grace_period" => 0
    "grace_interval" => "day"
    "invoice_period" => 1
    "invoice_interval" => "mounth"
    "tier" => 1
    "created_at" => "2022-11-04 22:15:21"
    "updated_at" => "2022-11-04 22:15:21"
    "deleted_at" => null
  ]
  #original: array:19 [▶]
  #changes: []
  #casts: array:14 [▶]
  #classCastCache: []
  #attributeCastCache: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #fillable: array:15 [▶]
  #guarded: array:1 [▶]
  #forceDeleting: false
}

Client Model :

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Bpuig\Subby\Traits\HasSubscriptions;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Client extends Model
{
    use HasFactory,HasSubscriptions;
    protected $fillable=['name','phone','email'];
}
bpuig commented 1 year ago

Hello, "mounths" is not a valid Carbon interval. You need to use month, week, day, etc: https://carbon.nesbot.com/docs/

This is the list of valid intervals: 'millennium', 'century', 'decade', 'year', 'quarter', 'month', 'week', 'weekday', 'day', 'hour', 'minute', 'second', 'millisecond', 'microsecond'