Astrotomic / laravel-translatable

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

request help some issue #249

Closed phagna closed 2 years ago

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

<?php

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

<?php

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?

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 7 days