PHP code example of ralphjsmit / laravel-filament-seo
1. Go to this page and download the library: Download ralphjsmit/laravel-filament-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' );
ralphjsmit / laravel-filament-seo example snippets
use Filament \Resources \Form ;
use RalphJSmit \Filament \SEO \SEO ;
public static function form (Form $form) : Form
{
return $form->schema([
SEO::make(),
]);
}
class Post extends Model
{
use HasSEO ;
}
namespace App \Filament \Resources ;
use App \Filament \Resources ;
use App \Models \Post ;
use Filament \Forms \Components \TextInput ;
use Filament \Resources \Form ;
use Filament \Resources \Resource ;
use Filament \Resources \Table ;
use RalphJSmit \Filament \SEO \SEO ;
class PostResource extends Resource
{
protected static ?string $model = Post::class;
protected static ?string $slug = 'posts' ;
protected static ?string $recordTitleAttribute = 'title' ;
protected static ?string $navigationGroup = 'Blog' ;
protected static ?string $navigationIcon = 'heroicon-o-document-text' ;
protected static ?int $navigationSort = 0 ;
public static function form (Form $form) : Form
{
return $form->schema([
TextInput::make('title' ),
SEO::make(),
]);
}
public static function table (Table $table) : Table
{
return $table->columns([ ]);
}
public static function getPages () : array
{
return [
'index' => Resources\PostResource\Pages\ListPosts::route('/' ),
'create' => Resources\PostResource\Pages\CreatePost::route('/create' ),
'edit' => Resources\PostResource\Pages\EditPost::route('{record}/edit' ),
];
}
}
namespace App \Http \Livewire ;
use App \Models \Post ;
use Filament \Forms \Components \Card ;
use Filament \Forms \Components \TextInput ;
use Filament \Forms \Concerns \InteractsWithForms ;
use Filament \Forms \Contracts \HasForms ;
use Illuminate \Contracts \View \View ;
use Illuminate \Database \Eloquent \Model ;
use Livewire \Component ;
use RalphJSmit \Filament \SEO \SEO ;
class CreatePost extends Component implements HasForms
{
use InteractsWithForms ;
public array $data = [];
public function mount () : void
{
$this ->form->fill();
}
public function render () : View
{
return view('livewire.create-post' );
}
protected function getFormSchema () : array
{
return [
TextInput::make('title' ),
Card::make([
SEO::make()
]),
];
}
protected function getFormStatePath () : ?string
{
return 'data' ;
}
protected function getFormModel () : Model |string |null
{
return Post::class;
}
public function submitForm ()
{
$post = Post::create($this ->form->getState());
$this ->form->model($post)->saveRelationships();
}
}
namespace App \Http \Livewire ;
use App \Models \Post ;
use Filament \Forms \Components \TextInput ;
use Filament \Forms \Concerns \InteractsWithForms ;
use Filament \Forms \Contracts \HasForms ;
use Illuminate \Contracts \View \View ;
use Illuminate \Database \Eloquent \Model ;
use Livewire \Component ;
use RalphJSmit \Filament \SEO \SEO ;
use RalphJSmit \Filament \SEO \Tests \Fixtures \Models \Post ;
class EditPost extends Component implements HasForms
{
use InteractsWithForms ;
public Post $post;
public function mount () : void
{
$this ->form->fill([
'title' => $this ->post->title,
]);
}
public function render () : View
{
return view('livewire.edit-post' );
}
protected function getFormSchema () : array
{
return [
TextInput::make('title' ),
SEO::make(),
];
}
protected function getFormModel () : Model |string |null
{
return $this ->post;
}
public function submitForm ()
{
$this ->post->update(
$this ->form->getState(),
);
}
}