Skip to main content

Helper Functions & Blade Directives

SaaSykit offers helper functions/directives to ease your life when building your SaaS application.

PHP Helpersโ€‹

User::isSubscribed()โ€‹

This helper function returns true if the user is subscribed to a plan, false otherwise.

You can also pass in the subscription product slug to the function to check if the user is subscribed to that specific product.

$user->isSubscribed('product-slug');

For SaaSykit Tenancy users, you can also pass in the Tenant to the function to check if the user is subscribed to a specific tenant.

$user->isSubscribed('product-slug', $tenant);

User::isTrialing()โ€‹

This helper function returns true if the user is trialing (subscribed to a plan and in trial period), false otherwise.

You can also pass in the subscription product slug to the function to check if the user is trialing that specific product.

$user->isTrialing('product-slug');

For SaaSykit Tenancy users, you can also pass in the Tenant to the function to check if the user is trialing a specific tenant.

$user->isTrialing('product-slug', $tenant);

User::hasPurchased()โ€‹

This helper function returns true if the user has purchased a product, false otherwise.

You can also pass in the one-time purchase product slug to the function to check if the user has purchased that specific product.

$user->hasPurchased('product-slug');

For SaaSykit Tenancy users, you can also pass in the Tenant to the function to check if the user has purchased a product in a specific tenant.

$user->hasPurchased('product-slug', $tenant);

SubscriptionManager::getUserSubscriptionProductMetadata(User $user)โ€‹

tip

This helper in only supported in SaaSykit, see below for the SaaSykit Tenancy version of this helper.

Each product can have a set of metadata that you define in the Admin Panel that is accessible to your application via this helper function.

You can use this metadata to store information about the product that you want to access in your application. For example, you can store the number of users allowed in the product, and then use this helper function to access that information in your application and display it to your users or check against it.

$metadata = SubscriptionManager::getUserSubscriptionProductMetadata($user);

This function will return an array of metadata for the user's subscription product.

[
'metadata_key1' => 'metadata_value1',
'metadata_key2' => 'metadata_value2',
]

If you enabled "Multiple Subscription Products" in the Admin Panel, this function will return an array of metadata for all the subscription products the user is subscribed to in the form of an array of arrays.

[
'product_slug1' => [
'metadata_key1' => 'metadata_value1',
'metadata_key2' => 'metadata_value2',
],
'product_slug2' => [
'metadata_key1' => 'metadata_value1',
'metadata_key2' => 'metadata_value2',
],
]
tip

You can also get the user subscription product metadata by using the function User::subscriptionProductMetadata(). So you can retrieve the metadata of the subscription product(s) of current logged in user by calling auth()->user()->subscriptionProductMetadata().

Refer back to Products for more information about that.

SubscriptionManager::getTenantSubscriptionProductMetadataโ€‹

tip

This helper in only supported in SaaSykit Tenancy, see above for the SaaSykit version of this helper.

Just like the SubscriptionManager::getUserSubscriptionProductMetadata helper function above, this function will return the metadata of the subscription product(s) of a specific tenant.

$metadata = SubscriptionManager::getTenantSubscriptionProductMetadata($tenant);

This function will return an array of metadata for the tenant's subscription product.

[
'metadata_key1' => 'metadata_value1',
'metadata_key2' => 'metadata_value2',
]

Blade Directivesโ€‹

@subscribedโ€‹

This directive will act as an if-statement and render the content if the user is subscribed to a plan.

@subscribed
<p>You are subscribed to a plan.</p>
@endsubscribed

You can also pass in the subscription product slug to the directive to check if the user is subscribed to that specific product.

@subscribed('product-slug')
<p>You are subscribed to the product with the slug 'product-slug'.</p>
@endsubscribed

For SaaSykit Tenancy users, you can also pass in the Tenant to the directive to check if the user is subscribed to a specific tenant.

@subscribed('product-slug', $tenant)
<p>You are subscribed to the product with the slug 'product-slug' in the tenant.</p>
@endsubscribed

@notsubscribedโ€‹

This directive will render the content if the user is not subscribed to a plan.

@notsubscribed
<p>You are not subscribed to a plan.</p>
@endnotsubscribed

You can also pass in the subscription product slug to the directive to check if the user is not subscribed to that specific product.

@notsubscribed('product-slug')
<p>You are not subscribed to the product with the slug 'product-slug'.</p>
@endnotsubscribed

For SaaSykit Tenancy users, you can also pass in the Tenant to the directive to check if the user is not subscribed to a specific tenant.

@notsubscribed('product-slug', $tenant)
<p>You are not subscribed to the product with the slug 'product-slug' in the tenant.</p>
@endnotsubscribed

@trialingโ€‹

This directive will render the content if the user is trialing.

@trialing
<p>You are trialing.</p>
@endtrialing

Same as the @subscribed directive, you can also pass in the subscription product slug to the directive to check if the user is trialing that specific product.

@trialing('product-slug')
<p>You are trialing the product with the slug 'product-slug'.</p>
@endtrialing

For SaaSykit Tenancy users, you can also pass in the Tenant to the directive to check if the user is trialing a specific tenant.

@trialing('product-slug', $tenant)
<p>You are trialing the product with the slug 'product-slug' in the tenant.</p>
@endtrialing

purchasedโ€‹

This directive will render the content if the user has purchased a product.

@purchased
<p>You have purchased a product.</p>
@endpurchased

You can also pass in the one-time purchase product slug to the directive to check if the user has purchased that specific product.

@purchased('product-slug')
<p>You have purchased the product with the slug 'product-slug'.</p>
@endpurchased

For SaaSykit Tenancy users, you can also pass in the Tenant to the directive to check if the user has purchased a product in a specific tenant.

@purchased('product-slug', $tenant)
<p>You have purchased the product with the slug 'product-slug' in the tenant.</p>
@endpurchased