Hello Devs, 

In this tutorial, we will learn Laravel Show Active Subscription Data Example

Laravel Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services. It handles almost all of the boilerplate subscription billing code you are dreading.

Follow this step by step guide below. 


Step 1 : Install Laravel Fresh App

composer create-project --prefer-dist laravel/laravel blog


Step 2 : Setup Database Configuration

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=Enter_Your_Database_Name
DB_USERNAME=Enter_Your_Database_Username
DB_PASSWORD=Enter_Your_Database_Password



Step 3 : Set Stripe API Key and SECRET

Create your stripe account first here


Get Stripe API Key and SECRET

.env

STRIPE_KEY=pk_test*****
STRIPE_SECRET=sk_test******


Step 4 : Add Route

routes/web.php

Route::get('/active-subscription', ['as'=>'home','uses'=>'SubscriptionController@index'])->name('subscription.index');


Step 5 : Create Controller

php artisan make:controller SubscriptionController


app/Http/SubscriptionController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
Use App\User;
use Stripe;
use Session;
use Exception;

class SubscriptionController extends Controller
{
    public function index()
    {
        $stripe = new \Stripe\StripeClient(env("STRIPE_SECRET"));

        $user = auth()->user();

        $dataActive = $stripe->subscriptions->all(['customer' => $user->stripe_id]);

        return view('subscription.index',compact('dataActive'));
    }
}



Step 6 : Create View File

resources/view/subscription/index.blade.php

<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Laravel</title>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body id="app-layout">
    <div class="container">
        <div class="row">
            <div class="col-md-12 col-md-offset-0">
                <h2>Subscription Active Data</h2>
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>Id</th>
                            <th>Ammont</th>
                            <th>Interval</th>
                            <th>End Date</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        @if(!empty($dataActive))
                            @foreach($dataActive->data as $key => $value)
                                <tr>
                                    <td>{{ ++$key }}</td>
                                    <td>{{ $value->plan->interval }}</td>
                                    <td>${{ $value->plan->amount/100 }}</td>
                                    <td>{{ date('Y-m-d',$value->current_period_end) }}</td>
                                    <td><a class="btn btn-danger" href="">Cancel Subscription</a> </td>
                                </tr>
                            @endforeach
                        @endif
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</body>
</html>


run below command for a quick peek

php artisan serve


Open this URL in your browser, 

http://localhost:8000/active-subscription


May this example help you.