laravel / cashier-paddle

Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.
https://laravel.com/docs/cashier-paddle
MIT License
246 stars 57 forks source link

Method Illuminate\Database\Eloquent\Collection::subscription does not exist. #77

Closed Benoit1980 closed 4 years ago

Benoit1980 commented 4 years ago

Hello,

        "php": "^7.4",
        "laravel/cashier-paddle": "^1.2.0",
        "laravel/framework": "^7.28.3",

When following the doc here: https://laravel.com/docs/7.x/cashier-paddle#past-and-upcoming-payments

By doing this:

        $user = User::where('id',Auth::id())->get();
        $nextPayment = $user->subscription('default');
        return view('backend.customer.orders.view', ['nextpayment', $nextPayment]);

I am getting:

BadMethodCallException
Method Illuminate\Database\Eloquent\Collection::subscription does not exist.

Any idea why please?

Thank you.

GrahamCampbell commented 4 years ago
$user = User::where('id',Auth::id())->get();

This doesn't return a user, it returns a collection of users. You need $user = User::firstWhere('id',Auth::id());

Benoit1980 commented 4 years ago

Thanks! I think some updates must have been released for the migrations because I have a missing column in my subscription column as I am getting this for:

        $nextPayment = $user->subscription('default');
        return view('backend.customer.orders.view', ['nextpayment', $nextPayment]);
Illuminate\Database\QueryException
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'subscriptions.billable_id' in 'where clause' (SQL: select * from `subscriptions` where `subscriptions`.`billable_id` = 48 and `subscriptions`.`billable_id` is not null and `subscriptions`.`billable_type` = App\User and `name` = default order by `created_at` desc limit 1)

And when I pass a subscription order, I keep having this:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'billable_id' in 'field list' (SQL: insert into `subscriptions` (`name`, `paddle_id`, `paddle_plan`, `paddle_status`, `quantity`, `trial_ends_at`, `billable_id`, `billable_type`, `updated_at`, `created_at`) values (default, 4608459, 622049, active, 1, ?, 48, App\User, 2020-09-27 19:16:06, 2020-09-27 19:16:06)) {"exception":"[object] (Illuminate\\Database\\QueryException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'billable_id' in 'field list' (SQL: insert into `subscriptions` (`name`, `paddle_id`, `paddle_plan`, `paddle_status`, `quantity`, `trial_ends_at`, `billable_id`, `billable_type`, `updated_at`, `created_at`) values (default, 4608459, 622049, active, 1, ?, 48, App\\User, 2020-09-27 19:16:06, 2020-09-27 19:16:06)) at

Both showing the billable_id being missing.

image

driesvints commented 4 years ago

Think you're still on an old beta release.

Benoit1980 commented 4 years ago

oh ok, is there a way to have access to the new migrations since the Beta or do I need to delete everything instead and restart a fresh installation? Thank you.

driesvints commented 4 years ago

Fresh is probably the best idea since a lot has changed since the early beta's.

Benoit1980 commented 4 years ago

Thank you so much for the fast reply. Will do :-)