Skip to content
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

Does not seem to work with astrotomic/laravel-translatable #2

Closed
dmitrijsmihailovs opened this issue Feb 13, 2024 · 4 comments
Closed

Comments

@dmitrijsmihailovs
Copy link

In readme it is mentioned it works with the dimsav/laravel-translatable, but it is not maintained anymore, but there is a fork of it https://github.com/Astrotomic/laravel-translatable

I have setup migration and model

Schema::create('blogs', function (Blueprint $table) {
 $table->id();
 $table->timestamp('published_at');
 $table->timestamps();
});

Schema::create('blog_translations', function (Blueprint $table) {
 $table->increments('id');
 $table->unsignedBigInteger('blog_id');
 $table->string('locale')->index();

 $table->string('title');
 $table->string('slug')->index();
 $table->text('content');

 $table->unique(['blog_id', 'locale']);
 $table->foreign('blog_id')->references('id')->on('blogs')->onDelete('cascade');
});

Blog.php

<?php

namespace App\Models;

use App\Models\Translations\BlogTranslation;
use Astrotomic\Translatable\Translatable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Blog extends Model
{
    use HasFactory;
    use Translatable;

    protected $guarded = [];

    public $translationModel = BlogTranslation::class;

    protected array $translatedAttributes = [
        'title',
        'slug',
        'content'
    ];
}

BlogTranslation.php

<?php

namespace App\Models\Translations;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class BlogTranslation extends Model
{
    use HasFactory;

    public $timestamps = false;

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

BlogResoure.php

public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Translate::make()
                    ->schema(fn(string $locale) => [
                        TextInput::make('title')
                            ->required()
                            ->live(200)
                            ->afterStateUpdated(fn(Set $set, ?string $state) => $set('slug.' . $locale, Str::slug($state))),

                        TextInput::make('slug')
                            ->required()
                            ->unique(BlogTranslation::class, 'slug', fn($record) => $record),

                        Textarea::make('content')
                            ->required()
                    ])->locales(['en', 'es'])
                    ->columnSpanFull(),

                DateTimePicker::make('published_at')
                    ->required()
            ]);
    }

But trying to create a record it throws error: Array to string conversion

@lam0819
Copy link
Contributor

lam0819 commented Feb 21, 2024

1 question , should your

protected array $translatedAttributes = [
'title',
'slug',
'content'
];

is BlogsTranslation Model ?

  1. if you dont use our plugin, can you save in filament form ?

@erenergul
Copy link

erenergul commented Feb 29, 2024

Did you solve with astrotomic package ? Please also let me know. I also use same package.

@dmitrijsmihailovs
Copy link
Author

I have not solved it. But looks to me this field needs ->relationship() method, to save data in blog_translations table.

@Sindu1374
Copy link

Hello, this is my first comment

@lam0819 lam0819 closed this as not planned Won't fix, can't repro, duplicate, stale May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants