Git Product home page Git Product logo

filament-translate-field's People

Contributors

cklei-carly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

filament-translate-field's Issues

Does not seem to work with astrotomic/laravel-translatable

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.