PHP code example of marshmallow / seoable

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

    

marshmallow / seoable example snippets


use Marshmallow\Seoable\Facades\Seo;

Seo::setTitle(string $title);
Seo::setDescription(string $description);
Seo::setKeywords(array $keywords);
Seo::setImage(string $image);
Seo::setFollowType(string $follow_type);

class YourEloquentModel extends Model
{
    use HasSlug;

    /**
     * Get the options for generating the slug.
     */
    public function getSlugOptions() : SlugOptions
    {
        return SlugOptions::create()
            ->generateSlugsFrom('name')
            ->saveSlugsTo('slug');
    }
}

use Marshmallow\Seoable\Seoable;

Seoable::routes();

// config/seo.php

return [
    'use_pretty_urls' => true,
];

$faq = \Marshmallow\Seoable\Helpers\Schemas\SchemaFaqPage::make();
$faq->addQuestionAndAnswer('What is the name of this company?', 'Marshmallow');

\Marshmallow\Seoable\Facades\Seo::addSchema($faq);


# app/Helpers/RobotTxt.php

namespace App\Helpers;

use Marshmallow\Seoable\Objects\Robots;
use Marshmallow\Seoable\Contracts\RobotTxtInterface;

class RobotTxt implements RobotTxtInterface
{
    public function handle(Robots $robots): Robots
    {
        return $robots->userAgent('*')
            ->allow('/')
            ->disallow('/login');
    }
}


return [

    /*
    |--------------------------------------------------------------------------
    | Robots.txt
    |--------------------------------------------------------------------------
    |
    | Override the class which builds the robots.txt file. If you are using this,
    | do not forget to delete the original public/robots.txt file.
    |
    */
    'robots_resolver' => App\Helpers\DefaultRobotsTxt::class,
];

php artisan migrate

php artisan vendor:publish --provider="Marshmallow\Seoable\ServiceProvider"

...
use Marshmallow\Seoable\Seoable;

class Page extends Resource
{
  ...
  public function fields(Request $request)
  {
    return [
      ...,
      Seoable::make('Seo'),
    ];
  }
}

use Marshmallow\Seoable\Facades\Seo;

class ExampleController extends Controller
{
    public function show (Product $product)
    {
        $product->useForSeo();

        return view('product')->with([
            'product' => $product
        ])
    }
}

bash
php artisan marshmallow:resource Route Seoable
php artisan marshmallow:resource PrettyUrl Seoable
bash
php artisan marshmallow:resource Route Seoable