(雄辩)显示客户的所有订阅,即使他没有付款
我有 4 个表、客户、计划、订阅和付款。
我想获取客户的所有订阅、他的计划以及他是否已付款,我已经尝试过此查询,但它无法按预期工作。
$data = Subscription::select('subscription_id')
->leftjoin('clients', 'clients.id', '=', 'subscriptions.client_id')
->leftjoin('plans', 'plans.id', '=', 'subscriptions.plan_id')
->leftjoin('payments', 'subscriptions.id', '=', 'subscriptions.id')
->where('clients.id', $id)
->get();
I have 4 tables, Clients, Plans, Subscriptions, and Payments.
I would like to get all the subscriptions of a client, his plan and if he has any payment made, I have tried this query, but it does not work as expected.
$data = Subscription::select('subscription_id')
->leftjoin('clients', 'clients.id', '=', 'subscriptions.client_id')
->leftjoin('plans', 'plans.id', '=', 'subscriptions.plan_id')
->leftjoin('payments', 'subscriptions.id', '=', 'subscriptions.id')
->where('clients.id', $id)
->get();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我是你,我会利用关系并这样做:
然后,检索所有的代码如下所示:
要了解有关 Laravel 关系的更多信息,请查看此链接:https://laravel.com/docs/9.x/eloquent-relationships
If I were you, I'd utilize relationships and do it like this:
And then, the code to retrieve all will look like the following:
To learn more about laravel relationships, check out this link: https://laravel.com/docs/9.x/eloquent-relationships