Laravel Translate Model (dimsav/laravel-translatable)

Official Doc


Main table: store_menu, translated table: store_menu_translations

Schema::create('store_menu', function (Blueprint $table) {

		Don't need to add columns need to be translated in main table

Schema::create('store_menu_translations', function (Blueprint $table) {
	I tried to use this column name to reference to main table, 
	but error occurs when saveing data and it says 'store_menu_m_id' not found.
	Have no idea where to change the rule

	// Columns need to be translated
	$table->string('subtitle', 255)->nullable();


Full example:

Controller to save data

$menu = new StoreMenuM;
$menu = TranslateM::to_translate_data($data, $menu);


namespace App\Models;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Config;
use Illuminate\Database\Eloquent\Model;

use Carbon\Carbon;

class TranslateM extends Model{

    static function to_translate_data($data, $model){
        $locales = Config::get('wikirex.locales');

        foreach ($data as $key => $value) {
            $match = null;
            foreach ($locales as $code => $locale) {
                preg_match('/^(.+)\_(' . $code . ')$/', $key, $match);
                if($match != false){

            if($match == false){
                $model->{$key} = $value;
                $model->translateOrNew($match[2])->{$match[1]} = $value;

        return $model;