Skip to content

Commit b3aad8c

Browse files
committed
Core translatable implementation
1 parent 999a886 commit b3aad8c

File tree

4 files changed

+821
-0
lines changed

4 files changed

+821
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php namespace October\Contracts\Database;
2+
3+
/**
4+
* TranslatableInterface
5+
*
6+
* @package october\contracts
7+
* @author Alexey Bobkov, Samuel Georges
8+
*/
9+
interface TranslatableInterface
10+
{
11+
/**
12+
* getTranslatableAttributes returns the list of translatable attribute names
13+
* @return array
14+
*/
15+
public function getTranslatableAttributes();
16+
17+
/**
18+
* isTranslatableAttribute checks if a given attribute is translatable
19+
* @return bool
20+
*/
21+
public function isTranslatableAttribute($key);
22+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use October\Rain\Database\Schema\Blueprint;
4+
use October\Rain\Database\Updates\Migration;
5+
6+
return new class extends Migration
7+
{
8+
public function up()
9+
{
10+
Schema::create('translate_attributes', function (Blueprint $table) {
11+
$table->increments('id');
12+
$table->string('model_type', 512);
13+
$table->integer('model_id');
14+
$table->string('locale', 16);
15+
$table->string('attribute', 128);
16+
$table->mediumText('value')->nullable();
17+
$table->index(
18+
['model_type', 'model_id', 'locale'],
19+
'translate_type_id_locale_index'
20+
);
21+
$table->unique(
22+
['model_type', 'model_id', 'locale', 'attribute'],
23+
'translate_unique_index'
24+
);
25+
});
26+
}
27+
28+
public function down()
29+
{
30+
Schema::dropIfExists('translate_attributes');
31+
}
32+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php namespace October\Rain\Database\Models;
2+
3+
use October\Rain\Database\Model;
4+
5+
/**
6+
* TranslateAttribute stores translated attribute values for translatable models
7+
*
8+
* @package october\database
9+
* @author Alexey Bobkov, Samuel Georges
10+
*/
11+
class TranslateAttribute extends Model
12+
{
13+
/**
14+
* @var string table associated with the model
15+
*/
16+
public $table = 'translate_attributes';
17+
18+
/**
19+
* @var bool timestamps
20+
*/
21+
public $timestamps = false;
22+
23+
/**
24+
* @var array fillable fields
25+
*/
26+
protected $fillable = ['locale', 'attribute', 'value'];
27+
28+
/**
29+
* @var array morphTo
30+
*/
31+
public $morphTo = [
32+
'model' => []
33+
];
34+
}

0 commit comments

Comments
 (0)