PHP code example of nextdevit / ndit-license-client
1. Go to this page and download the library: Download nextdevit/ndit-license-client 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/ */
nextdevit / ndit-license-client example snippets
// routes/web.php
Route::get('/setup/license', [LicenseSetupController::class, 'show'])->name('ndit-license.activate');
Route::post('/setup/license', [LicenseSetupController::class, 'store'])->name('ndit-license.activate.store');
class LicenseSetupController extends Controller
{
public function show(): Response
{
return Inertia::render('NditLicenseActivate', [
'shareable' => NditLicense::shareable(),
'submitUrl' => route('ndit-license.activate.store'),
'portalUrl' => 'https://app.nextdevit.com/portal',
'continueUrl' => route('setup.step-1'),
't' => trans('ndit-license::activate') + ['errors' => trans('ndit-license::errors')],
]);
}
public function store(Request $request): RedirectResponse
{
$result = NditLicense::activate($request->string('key')->toString());
return back()->with('ndit_result', [
'ok' => $result->ok(),
'error_code' => $result->errorCode(),
'message' => $result->message(),
'activation_summary' => $result->activationSummary(),
'retry_after' => $result->retryAfter(),
]);
}
}
Route::middleware(['auth', 'ndit-licensed'])->group(function () {
// admin routes
});
// route middleware
Route::middleware('entitled:module.accounting')->group(/* … */);
// in code
if (NditLicense::can('module.accounting')) { /* … */ }
// in Blade — note the space: Blade will not compile `yes@endentitled`
@entitled('module.accounting') … @else … @endentitled
@notentitled('module.accounting') … @endnotentitled
// composed into a policy
Gate::allows('ndit-entitled', 'module.accounting');
public function share(Request $request): array
{
return [...parent::share($request), 'license' => NditLicense::shareable()];
}
class SyncModuleRegistry
{
public function handle(EntitlementsUpdated $event): void
{
foreach (array_diff($event->new, $event->old) as $added) { /* enable */ }
foreach (array_diff($event->old, $event->new) as $removed) { /* retire */ }
}
}
// routes/console.php
Schedule::command('ndit-license:heartbeat')->everySixHours()->withoutOverlapping();
Route::middleware(['auth', 'ndit-license.opportunistic'])->group(/* admin */);
NditLicense::telemetry(['niche' => config('karbar.niche')]);
bash
php artisan vendor:publish --tag=ndit-license-config
bash
php artisan vendor:publish --tag=ndit-license-vue
php artisan vendor:publish --tag=ndit-license-lang # optional, to reword copy