Astrotomic / laravel-translatable

A Laravel package for multilingual models
https://docs.astrotomic.info/laravel-translatable/
MIT License
1.23k stars 156 forks source link

Add methods getTranslationChanges() and wasTranslationChanged() #231

Closed Tschoatscho closed 1 year ago

Tschoatscho commented 3 years ago

According to @Gummibeer 's suggestion added method getTranslationChanges() (no overrides or breaking changes). For completeness in analogy to Laravel model's wasChanged() also added method wasTranslationChanged(). Both methods are covered by additional unit tests.

Could not resist to fix a typo in an existing unit test.

Dependencies allow Illuminate/Laravel 8 where Factories have been removed. Therefore needed to add laravel/legacy-factories.

The first commit 'Prettified Code!' was created by a Github Action which is defined within the original repository. I just changed the default branch's name to 'main' which triggered the action. As the action seems to be defined by the maintainer I assume its results are intended (although they blow up this PR).

I'm not sure whether and where I should update the docs. Would appreciate any suggestions.

Gummibeer commented 3 years ago

Hey, there was an issue in the GitHub Action doing the first commit on the main branch. Could you click "fetch upstream" button on your fork? 🙂 That should fix it - I will ignore the markdown files for the moment.

Tschoatscho commented 3 years ago

Could you click "fetch upstream" button on your fork? 🙂

Done (again) 🙂

That should fix it - I will ignore the markdown files for the moment.

Until now it didn't ... If we can't get the PR clean this way (after giving Github time to refresh) I could create a new PR only with the 2 (3 with typo fix) relevant commits (would also clear my error with legacy-factories).

phagna commented 2 years ago

Dear Developer! I have some problem with this package like below:

Schema::create('posts', function(Blueprint $table) {
    $table->increments('id');
    $table->string('author');
   $table ->boolean('is_active');
    $table->timestamps();
});

//Post Model

namespace App\Models;

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Eloquent\Model;
use Astrotomic\Translatable\Translatable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
// use Astrotomic\Translatable\Contracts\Translatable as TranslatableContract;

class Post extends Model implements TranslatableContract
{
    use HasFactory, Translatable;

    public function __construct(array $attributes = [])
    {
      $this->fillable = Schema::getColumnListing($this->getTable());
      parent::__construct($attributes);
    }
    // protected $guarded = ['id'];
    public $translatedAttributes = ['title', 'full_text'];
}

//PostTranslation Model

namespace App\Models;

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

class PostTranslation extends Model
{
    use HasFactory;

    public $timestamps = false;
    protected $fillable = ['author','title', 'full_text'];
}

//Controller

    public function store(Request $request)
    {
      $request->request->add(['author'=> auth()->user()->name]);
      $request->request->add(['is_active'=> 1]);
      Post::create($request->validated());
      return redirect()->route('dashboard');
    }

when submit the form it save only ('title','content') to table post_translations only. so what problem with it?

Tschoatscho commented 2 years ago

TBH, I don't really understand what you want to achieve with your code. is_active is a boolean you should not try to translate it, same with author name. Maybe you better make your changes in the Post model and not in the PostTranslation model. BTW, this discussion refers to a pull request on laravel-translatable and not to the laravel-translatable itself.

Gummibeer commented 2 years ago

BTW, this discussion refers to a pull request on laravel-translatable and not to the laravel-translatable itself.

👍

Please open an issue for your problem.

dmtar commented 2 years ago

Are you planning to merge this any time soon?