Skip to content

Commit

Permalink
feat: add SEOSection component
Browse files Browse the repository at this point in the history
  • Loading branch information
ast21 committed Jul 6, 2023
1 parent 25cd519 commit a465f7e
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 22 deletions.
9 changes: 5 additions & 4 deletions database/migrations/create_admin_kit_seo_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ return new class extends Migration
{
Schema::create('admin_kit_seo', function (Blueprint $table) {
$table->id();

// add fields
$table->jsonb('title')->default('{}');

$table->unsignedBigInteger('seoable_id');
$table->string('seoable_type');
$table->string('title', 70)->nullable();
$table->string('description', 300)->nullable();
$table->string('keywords', 255)->nullable();
$table->timestamps();
});
}
Expand Down
13 changes: 4 additions & 9 deletions resources/lang/en/seo.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
<?php

return [
'resource' => [
'label' => 'SEO',
'plural_label' => 'SEO',
'group_name' => 'SEO Settings',

'id' => 'ID',
'title' => 'Title',

'created_at' => 'Создан',
'updated_at' => 'Обновлен',
],
'title' => 'Title',
'description' => 'Description',
'keywords' => 'Keywords',
];
13 changes: 4 additions & 9 deletions resources/lang/ru/seo.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
<?php

return [
'resource' => [
'label' => 'SEO',
'plural_label' => 'SEO',
'group_name' => 'Настройки SEO',

'id' => 'ID',
'title' => 'Title',

'created_at' => 'Создан',
'updated_at' => 'Обновлен',
],
'title' => 'Заголовок',
'description' => 'Описание',
'keywords' => 'Ключевые слова',
];
Empty file removed resources/views/.gitkeep
Empty file.
34 changes: 34 additions & 0 deletions src/Forms/Components/SEOSection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace AdminKit\SEO\Forms\Components;

use Filament\Forms\Components\Section;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;

class SEOSection
{
public static function make()
{
return Section::make(__('admin-kit-seo::seo.group_name'))
->relationship('seo')
->schema([
TextInput::make('title')
->label(__('admin-kit-seo::seo.title'))
->maxLength(70)
->columnSpan(2),

Textarea::make('description')
->label(__('admin-kit-seo::seo.description'))
->maxLength(300)
->rows(3)
->columnSpan(2),

Textarea::make('keywords')
->label(__('admin-kit-seo::seo.keywords'))
->maxLength(255)
->rows(3)
->columnSpan(2),
]);
}
}
7 changes: 7 additions & 0 deletions src/Models/SEO.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@ class SEO extends AbstractModel

protected $fillable = [
'title',
'description',
'keywords',
];

public function seoable()
{
return $this->morphTo();
}
}
14 changes: 14 additions & 0 deletions src/Traits/HasSEO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace AdminKit\SEO\Traits;

use AdminKit\SEO\Models\SEO;
use Illuminate\Database\Eloquent\Relations\MorphOne;

trait HasSEO
{
public function seo(): MorphOne
{
return $this->morphOne(SEO::class, 'seoable');
}
}

0 comments on commit a465f7e

Please sign in to comment.