PHP code example of surface / laravel-webfinger

1. Go to this page and download the library: Download surface/laravel-webfinger 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/ */

    

surface / laravel-webfinger example snippets


use App\Http\Resources\Webfinger as WebfingerResource;
use Surface\LaravelWebfinger\Http\Resources\Webfinger as PackageWebfinger;
use Surface\LaravelWebfinger\Service\Webfinger as WebfingerService;

$this->app->bind(
    PackageWebfinger::class,
    static fn (Container $app): WebfingerResource => new WebfingerResource(
        ...$app->make(WebfingerService::class)
    )
);



namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Support\Stringable;
use Surface\LaravelWebfinger\Http\Resources\Webfinger as JsonResource;

class Webfinger extends JsonResource
{
    protected string $website;

    public function __construct(protected Stringable $instance, protected Stringable $username)
    {
        parent::__construct($instance, $username);

        $this->website = 'https://www.example.com';
    }

    public function links(Request $request): array
    {
        return [
            ...parent::links($request),
            [
                'rel' => 'self',
                'type' => 'text/html',
                'href' => $this->website,
            ],
        ];
    }
}
bash
php artisan vendor:publish --provider="Surface\LaravelWebfinger\LaravelWebfingerServiceProvider"