PHP code example of vnuswilliams / squarhe-subscription
1. Go to this page and download the library: Download vnuswilliams/squarhe-subscription library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vnuswilliams / squarhe-subscription example snippets
namespace App\Models;
use Squarhe\Subscription\Models\Concerns\HasSubscriptions;
class User
{
use HasSubscriptions;
}
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Squarhe\Subscription\Enums\PeriodicityType;
use Squarhe\Subscription\Models\Feature;
class FeatureSeeder extends Seeder
{
public function run()
{
$deployMinutes = Feature::create([
'consumable' => true,
'name' => 'deploy-minutes',
'periodicity_type' => PeriodicityType::Day,
'periodicity' => 1,
]);
$customDomain = Feature::create([
'consumable' => false,
'name' => 'custom-domain',
]);
}
}
use Illuminate\Support\Facades\Gate;
public function boot(): void
{
Gate::define('create-project', function ($user) {
return $user->hasEnoughCharges('deploy-minutes');
});
Gate::define('use-custom-domain', function ($user) {
return $user->canUseFeature('custom-domain');
});
}
public function store(Request $request)
{
$this->authorize('create-project');
// Perform business action...
auth()->user()->consume('deploy-minutes');
}