1. Go to this page and download the library: Download despark/laravel-db-i18n library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
despark / laravel-db-i18n example snippets
...
'languages' => [
// Add languages that you will use in your app.
[
'locale' => 'en',
'name' => 'English',
],
[
'locale' => 'de',
'name' => 'Deutsche',
],
[
'locale' => 'fr',
'name' => 'Français',
],
],
...
...
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('articles', function (Blueprint $table) {
$table->increments('id');
$table->string('url');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('articles');
}
...
...
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('articles_i18n', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('parent_id');
$table->string('locale');
$table->string('title');
$table->text('content')->nullable();
$table->timestamps();
$table->foreign('parent_id')
->references('id')
->on('articles')
->onDelete('cascade')
->onUpdate('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('articles_i18n');
}
...
...
use Despark\Cms\Models\AdminModel;
use Despark\LaravelDbLocalization\Contracts\Translatable;
use Despark\LaravelDbLocalization\Traits\HasTranslation;
class Article extends AdminModel implements Translatable
{
use HasTranslation;
protected $table = 'articles';
protected $translatable = [
'title',
'content',
];
protected $fillable = [
'title',
'content',
'url',
];
protected $rules = [
'title' => '
...
use Despark\Cms\Http\Controllers\AdminController;
class ArticlesController extends AdminController
{
}
...