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');

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');

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');

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

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.

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

@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>
@notSubscribed

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>
@notSubscribed

@trialingโ€‹

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

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

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>
@trialing

purchasedโ€‹

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

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

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>
@purchased