PHP code example of kanuni / laravel-blade-anchor

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

    

kanuni / laravel-blade-anchor example snippets


namespace App\BladeExtenders;

use Illuminate\Contracts\Support\Renderable;
use Kanuni\LaravelBladeAnchor\Contracts\AnchorExtender;

class WelcomePageExtender implements AnchorExtender
{
    public function __invoke(?array $variables): string|Renderable|null
    {
        return '<p>This string will be injected at anchor point.</p>';
    }
}

public function __invoke(?array $variables): string|Renderable|null
{
    return view('my-custom-blade-view', $variables);
}

class WelcomePageExtender implements AnchorExtender
{
    public function __construct(
        protected YourService $service
    )
    {}

    public function __invoke(?array $variables): string|Renderable|null
    {
        return "<p>This are the results of your service: {$this->service->getResults()}</p>";
    }
}

use Kanuni\LaravelBladeAnchor\Facades\LaravelBladeAnchor;
use App\BladeExtenders\WelcomePageExtender;

public function boot(): void
{
    LaravelBladeAnchor::registerExtender(
        view: 'welcome',
        anchor: 'begin.body',
        extenderClass: WelcomePageExtender::class,
    );
}

php artisan make:anchor-extender WelcomePageExtender