PHP code example of abdur-rahaman / laravel-seo

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

    

abdur-rahaman / laravel-seo example snippets


use Abdurrahaman\LaravelSeo\DTOs\SeoData;

public function update(Request $request, Post $post)
{
    $data = $request->validate([
        'title' => ['
    if (! empty($data['seo'])) {
        $post->updateSeo(SeoData::fromArray($data['seo']));
    }

    return back()->with('success', 'Saved.');
}



namespace App\Models;

use Abdurrahaman\LaravelSeo\Support\HasSeo;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use HasSeo;

    protected $fillable = ['title', 'slug', 'body'];
}

// Relation
$post->seo;

// Create / update SEO
$post->updateSeo([
    'title'          => 'My Post Title',
    'description'    => 'Meta description here.',
    'focus_keyword'  => 'laravel seo',
    'keywords'       => ['laravel', 'seo'],
    'canonical_url'  => url()->current(),
    'og_title'       => 'Share title',
    'og_description' => 'Share description',
    'og_image'       => asset('images/og.jpg'),
    'twitter_title'  => 'Twitter title',
    'twitter_image'  => asset('images/twitter.jpg'),
    'robots_index'   => true,
    'robots_follow'  => true,
    'schema_type'    => 'Article',
]);

// Helpers
$post->hasSeo();   // bool
$post->deleteSeo();

use Abdurrahaman\LaravelSeo\Facades\SEO;

public function show(Post $post)
{
    SEO::for($post);

    return view('posts.show', compact('post'));
}

SEO::for($post);

if (! $post->hasSeo()) {
    SEO::setTitle($post->title)
        ->setDescription(str($post->body)->limit(150)->toString());
}

use Abdurrahaman\LaravelSeo\Facades\SEO;

SEO::setTitle('About Us')
    ->setDescription('About our company.')
    ->setKeyword('about us')
    ->setImage(asset('images/about.jpg'))
    ->setCanonical(url('/about'));

laravel_seo()
    ->title('About Us')
    ->description('About our company.')
    ->keyword('about us')
    ->image(asset('images/about.jpg'));

'ai' => [
    'enabled' => true,
    'middleware' => ['web', 'auth'], // 
bash
php artisan seo:install
php artisan migrate
bash
php artisan seo:publish-assets
bash
php artisan vendor:publish --tag=laravel-seo-config
bash
php artisan vendor:publish --tag=laravel-seo-config
bash
php artisan seo:publish-assets --force