Installation Add the bundle via Composer:
composer require bprs/applink-bundle
Register the bundle in config/app.php under extra.bundles:
Bprs\AppLinkBundle\AppLinkBundle::class => ['all' => true],
Configuration Publish the default config:
php artisan vendor:publish --provider="Bprs\AppLinkBundle\AppLinkBundle" --tag="config"
Update config/applink.php with your app’s deep-linking scheme (e.g., myapp://).
First Use Case Generate a deep link in a controller or Blade template:
use Bprs\AppLinkBundle\Generator\DeepLinkGenerator;
$generator = new DeepLinkGenerator();
$deepLink = $generator->generate('user/profile', ['id' => 123]);
// Output: "myapp://user/profile?id=123"
Generating Links
Use the DeepLinkGenerator to create platform-specific links (iOS/Android):
$generator = app(DeepLinkGenerator::class);
$link = $generator->generate('checkout', ['cart_id' => 'abc123']);
Handling Incoming Links
Register a route to capture deep links (e.g., app/handle-deep-link):
Route::get('/handle-deep-link', [AppLinkController::class, 'handle']);
Parse incoming links in the controller:
use Bprs\AppLinkBundle\Parser\DeepLinkParser;
$parser = new DeepLinkParser();
$params = $parser->parse($request->getUri());
// $params = ['route' => 'user/profile', 'id' => 123]
Blade Integration Create a custom Blade directive for convenience:
Blade::directive('applink', function ($route) {
return "<?php echo app(\\Bprs\\AppLinkBundle\\Generator\\DeepLinkGenerator::class)->generate({$route}); ?>";
});
Usage in Blade:
<a href="{{ applink('product/view', ['id' => $product->id]) }}">View in App</a>
$generator->setScheme(config('applink.scheme.staging'));
$generator->setFallbackUrl('https://web.example.com');
public function handle($request, Closure $next) {
if ($request->hasDeepLink()) {
event(new DeepLinkOpened($request->getDeepLink()));
}
return $next($request);
}
Scheme Validation
myapp://) matches the app’s Info.plist (iOS) or AndroidManifest.xml (Android).x-callback-url for iOS 9+ compatibility:
$generator->setScheme('x-callback-url://myapp');
Query Parameter Escaping
?name=John%20Doe) may break parsing. Use rawurlencode:
$params = ['name' => rawurlencode('John Doe')];
Route Mismatches
config/applink.php matches the generated link’s path.$generator->setDebug(true); // Logs to storage/logs/applink.log
php artisan applink:validate to test parsing logic with sample URLs.Custom Parsers
Extend DeepLinkParser to handle non-standard formats:
class CustomParser extends DeepLinkParser {
protected function parseCustomFormat(string $uri): array {
// Custom logic
}
}
Register via service provider:
$this->app->bind(DeepLinkParser::class, CustomParser::class);
Middleware for Security Restrict deep link handling to authenticated users:
public function handle($request, Closure $next) {
if ($request->hasDeepLink() && !$request->user()) {
abort(403);
}
return $next($request);
}
Environment-Specific Config Use Laravel’s config caching to avoid runtime overrides:
php artisan config:cache
How can I help you explore Laravel packages today?