PHP code example of yotech-ai / twill-cms-seo-suite

1. Go to this page and download the library: Download yotech-ai/twill-cms-seo-suite 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/ */

    

yotech-ai / twill-cms-seo-suite example snippets


// app/Models/Article.php
use TwillSeo\Models\Behaviors\HasSeo;

class Article extends Model
{
    use HasBlocks, HasMedias, HasSeo, HasSlug, HasTranslation;
}

// app/Repositories/ArticleRepository.php
use TwillSeo\Repositories\Behaviors\HandleSeo;

class ArticleRepository extends ModuleRepository
{
    // HandleSeo must come AFTER HandleTranslations: HandleTranslations
    // rebuilds $fields['translations'] from scratch, which would wipe out
    // anything HandleSeo already injected there if it ran first.
    use HandleBlocks, HandleMedias, HandleSlugs, HandleTranslations, HandleSeo;
}

// config/twill-seo.php
'models' => [
    'articles' => [
        'model' => App\Models\Article::class,
        'title_attribute' => 'title',
        'schema_type' => 'Article',
    ],
],

// app/Http/Controllers/Twill/ArticleController.php
public function getForm(TwillModelContract $model): Form
{
    $form = parent::getForm($model);
    $form->addFieldset(SeoFields::fieldset());

    return $form;
}

// app/Http/Controllers/Twill/ArticleController.php
use A17\Twill\Services\Listings\TableColumns;
use TwillSeo\Services\Listings\ReadabilityScoreColumn;
use TwillSeo\Services\Listings\SeoScoreColumn;

class ArticleController extends ModuleController
{
    protected function setUpController(): void
    {
        // Each cell reads $model->seo(app()->getLocale()), which lazy-loads
        // a seoEntry relation per row unless eager-loaded here.
        $this->eagerLoadListingRelations(['seoEntry.translations']);
    }

    protected function additionalIndexTableColumns(): TableColumns
    {
        return TableColumns::make()
            ->add(SeoScoreColumn::make())
            ->add(ReadabilityScoreColumn::make());
    }
}
bash
php artisan twill-seo:install && php artisan migrate
blade
{{-- resources/views/layouts/app.blade.php --}}
<x-twill-seo::head :model="$article ?? null" />