Extending the package | laravel-html | Spatie       

 SPATIE  

  Laravel HTML 
===============

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-html](https://spatie.be/docs/laravel-html/v3)  General-usage  Extending the package

 Version   v3   v2   v1      

 Other versions for crawler [v3](https://spatie.be/docs/laravel-html/v3) [v2](https://spatie.be/docs/laravel-html/v2) [v1](https://spatie.be/docs/laravel-html/v1) 

  Extending the package    
- [ Introduction ](https://spatie.be/docs/laravel-html/v3/introduction)
- [ Postcardware ](https://spatie.be/docs/laravel-html/v3/postcardware)
- [ Installation &amp; setup in Laravel ](https://spatie.be/docs/laravel-html/v3/installation-setup)
- [ Upgrading ](https://spatie.be/docs/laravel-html/v3/upgrading)
- [ Questions and issues ](https://spatie.be/docs/laravel-html/v3/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-html/v3/changelog)

General usage
-------------

- [ Core concepts ](https://spatie.be/docs/laravel-html/v3/general-usage/core-concepts)
- [ Extending the package ](https://spatie.be/docs/laravel-html/v3/general-usage/extending)
- [ HTML builder ](https://spatie.be/docs/laravel-html/v3/general-usage/html-builder)
- [ Element classes ](https://spatie.be/docs/laravel-html/v3/general-usage/element-classes)
- [ Element methods ](https://spatie.be/docs/laravel-html/v3/general-usage/element-methods)
- [ The class() helper ](https://spatie.be/docs/laravel-html/v3/general-usage/the-class-helper)

 Extending the package
=====================

If you want to extend the Html package, you can do the following.

Create a class that extends Html:

```
<?php

namespace App\Services;

use Spatie\Html\Elements\Div;
use Spatie\Html\Html;

class HtmlExtended extends Html
{
    public function yesNoRadio($name = null, $model = null)
    {
        return Div::create()->addChildren(
            Div::create()->class('form-check form-check-inline')
                ->addChildren($this->radio($name)->class('form-check-input')->id($name.'_yes')->value(1)->checked(old($name) === '1' || $model[$name] === 1))
                ->addChildren($this->label('Yes')->for($name.'_yes')->class('form-check-label'))
        )->addChildren(
            Div::create()->class('form-check form-check-inline')
                ->addChildren($this->radio($name)->class('form-check-input')->id($name.'_no')->value(0)->checked(old($name) === '0' || $model[$name] === 0))
                ->addChildren($this->label('No')->for($name.'_no')->class('form-check-label'))
        );
    }
}
```

Re-Register the class in the AppServiceProvider:

```
<?php

namespace App\Providers;

use App\Helpers\HtmlExtended;
use Illuminate\Support\ServiceProvider;
use Spatie\Html\Html;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        $this->app->singleton(Html::class, HtmlExtended::class);
    }
}
```

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
