-
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Request]: Support Spatie Translatable plugin #55
Comments
why is this a bug? |
Hi @Eyvazov I don't think this plugin has any advantage in directly supporting Spatie Translatable Plugin. The problemNot everyone who uses it will need to translate their content. So if the plugin natively supports the translatable plugin, it's an additional dependency for those who don't want to use it. The solutionYou can install the Spatie plugin, and make the following modifications:
public function up(): void
{
Schema::create(config('filament-menu-builder.tables.menus'), static function (Blueprint $table): void {
$table->id();
$table->json('name');
$table->boolean('is_visible')->default(true);
$table->timestamps();
});
Schema::create(config('filament-menu-builder.tables.menu_items'), static function (Blueprint $table): void {
$table->id();
$table->foreignIdFor(Menu::class)->constrained()->cascadeOnDelete();
$table->foreignIdFor(MenuItem::class, 'parent_id')->nullable()->constrained($table->getTable())->nullOnDelete();
$table->nullableMorphs('linkable');
$table->json('title');
$table->string('url')->nullable();
$table->string('target', 10)->default(LinkTarget::Self);
$table->integer('order')->default(0);
$table->timestamps();
});
Schema::create(config('filament-menu-builder.tables.menu_locations'), static function (Blueprint $table): void {
$table->id();
$table->foreignIdFor(Menu::class)->constrained()->cascadeOnDelete();
$table->string('location')->unique();
$table->timestamps();
});
}
Example with the Menu Model namespace App\Models;
use Datlechin\FilamentMenuBuilder\Models\Menu as Model;
use Spatie\Translatable\HasTranslations;
class Menu extends Model
{
use HasTranslations;
protected $casts = [
'is_visible' => 'boolean',
];
/**
* @var array|string[]
*/
public array $translatable = ['name'];
}
namespace App\Filament\Resources;
use App\Filament\Resources\MenuResource\Pages;
use Datlechin\FilamentMenuBuilder\Resources\MenuResource as BaseMenuResource;
use Filament\Resources\Concerns\Translatable;
final class MenuResource extends BaseMenuResource
{
use Translatable;
public static function getPages(): array
{
return [
'index' => Pages\ListMenus::route('/'),
'edit' => Pages\EditMenu::route('/{record}/edit'),
];
}
} Finally, modify your PanelProvider to look like this use App\Filament\Resources\MenuResource;
use App\Models\Menu;
use App\Models\MenuItem;
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->plugins([
SpatieLaravelTranslatablePlugin::make()
->defaultLocales(['fr', 'en']),
FilamentMenuBuilderPlugin::make()
->usingResource(MenuResource::class)
->usingMenuModel(Menu::class)
->usingMenuItemModel(MenuItem::class),
])
} Hope this will help. |
Hi @Eyvazov |
What happened?
How can I make filament-menu-builder plugin multilingual with Filament spatie translatable plugin?
How to reproduce the bug
How can I make filament-menu-builder plugin multilingual with Filament spatie translatable plugin?
Package Version
0.6.0
PHP Version
8.1
Laravel Version
10.10
Which operating systems does with happen with?
No response
Notes
No response
The text was updated successfully, but these errors were encountered: