1
- # Laravel DB Localization
1
+ # Laravel DB Localization for laravel 5.1
2
2
3
3
## Installation
4
4
5
5
Open ` composer.json ` file of your project and add the following to the require array:
6
6
``` json
7
- "despark/laravel-db-localization" : " 1.2 .*"
7
+ "despark/laravel-db-localization" : " 2.0 .*"
8
8
```
9
9
10
10
Now run ` composer update ` to install the new requirement.
11
11
12
- Once it's installed, you need to register the service provider in ` app/ config/app.php` in the providers array:
12
+ Once it's installed, you need to register the service provider in ` config/app.php ` in the providers array:
13
13
``` php
14
14
'providers' => array(
15
15
...
16
- ' Despark\LaravelDbLocalization\LaravelDbLocalizationServiceProvider' ,
16
+ Despark\LaravelDbLocalization\LaravelDbLocalizationServiceProvider::class ,
17
17
);
18
18
```
19
19
20
20
Publish the config file:
21
- ` php artisan config :publish despark/laravel-db-localization `
21
+ ` php artisan vendor :publish --provider="Despark\LaravelDbLocalization\LaravelDbLocalizationServiceProvider" --tag="config" `
22
22
23
23
# How to use it
24
24
@@ -68,9 +68,12 @@ Schema::create('contacts_i18n', function (Blueprint $table) {
68
68
```
69
69
## Model Example
70
70
``` php
71
+
72
+ use Despark\LaravelDbLocalization\i18nModelTrait;
73
+
71
74
class Contacts extends Eloquent
72
75
{
73
- use Despark\LaravelDbLocalization\ i18nModelTrait; // You must use i18nModelTrait
76
+ use i18nModelTrait; // You must use i18nModelTrait
74
77
75
78
protected $fillable = [
76
79
'fax',
@@ -89,20 +92,18 @@ class Contacts extends Eloquent
89
92
class ContactsI18n extends Eloquent
90
93
{
91
94
protected $table = 'contacts_i18n';
92
-
93
- protected $fillable = ['contact_id', 'i18n_id', 'name', 'location'];
94
95
}
95
96
```
96
97
## View example
97
98
98
99
Create
99
100
``` php
100
- {{ Form::text("fax", null) } }
101
- {{ Form::text("phone", null) } }
101
+ {!! Form::text("fax", null) !! }
102
+ {!! Form::text("phone", null) !! }
102
103
103
104
@foreach($languages as $language)
104
- {{ Form::text("name[name_$language->id]", null) } } // Follow this convention array( fieldname_languageId );
105
- {{ Form::text("location[location_$language->id]", null) } }
105
+ {!! Form::text("name[name_$language->id]", null) !! } // Follow this convention array( fieldname_languageId );
106
+ {!! Form::text("location[location_$language->id]", null) !! }
106
107
@endforeach
107
108
```
108
109
Retrieve
@@ -117,23 +118,10 @@ Retrieve
117
118
$contacts->translate($i18nId)->location; // specific field
118
119
```
119
120
120
-
121
121
## Config Example
122
122
``` php
123
- app/ config/packages/despark/ laravel-db-localization/config .php
123
+ config/laravel-db-localization.php
124
124
'locale_class' => 'Despark\LaravelDbLocalization\I18n',
125
125
```
126
126
127
- ## If you want to checkout our example you need to follow this commands:
128
-
129
- Execute migrations with the following command
130
- ` php artisan migrate --package="despark/laravel-db-localization" `
131
-
132
- This will create tables ` i18n ` , ` contacts ` , ` contacts_i18n ` .
133
-
134
- Now you must seed ` i18n ` table:
135
- ` php artisan db:seed --class="Despark\LaravelDbLocalization\DatabaseSeeder" `
136
-
137
- Now you can check how it works:
138
- http://yourdomain.name/localization_example/
139
127
0 commit comments