@@ -112,26 +112,35 @@ public function translate($locale = false)
112
112
113
113
public function scopeWithTranslations ($ query , $ locale = null , $ softDelete = null )
114
114
{
115
+ // get i18n id by locale
115
116
$ i18nId = $ this ->getI18nId ($ locale );
117
+
116
118
$ translatorTable = new $ this ->translator ();
117
119
$ translatorTableName = $ translatorTable ->getTable ();
118
- $ transfield = $ this ->getTranslatorField ();
119
- $ table = $ this ->getTable ();
120
+ $ translatableTable = $ this ->getTable ();
121
+
122
+ $ translatorField = $ this ->getTranslatorField ();
120
123
$ localeField = $ this ->getLocaleField ();
121
124
122
125
if (! $ locale ) {
123
126
$ query = $ query ->leftJoin (
124
127
$ translatorTableName ,
125
- $ translatorTableName .'. ' .$ transfield , '= ' , $ table .'.id ' );
128
+ $ translatorTableName .'. ' .$ translatorField , '= ' , $ translatableTable .'.id ' );
126
129
} else {
130
+ $ aliasSoftDelete = '' ;
131
+ if ($ softDelete ) {
132
+ $ aliasSoftDelete = 'AND translatorAlias.deleted_at is null ' ;
133
+ }
134
+
127
135
$ query = $ query ->leftJoin (\DB ::raw (
128
136
'( SELECT
129
137
translatorAlias.*
130
138
FROM ' .$ translatorTableName .' as translatorAlias
131
139
WHERE translatorAlias. ' .$ localeField .' = ' .$ i18nId .'
140
+ ' .$ aliasSoftDelete .'
132
141
) as ' .$ translatorTableName
133
- ), function ($ join ) use ($ translatorTableName , $ transfield , $ table ) {
134
- $ join ->on ($ translatorTableName .'. ' .$ transfield , '= ' , $ table .'.id ' );
142
+ ), function ($ join ) use ($ translatorTableName , $ translatorField , $ translatableTable ) {
143
+ $ join ->on ($ translatorTableName .'. ' .$ translatorField , '= ' , $ translatableTable .'.id ' );
135
144
});
136
145
}
137
146
@@ -142,20 +151,6 @@ public function scopeWithTranslations($query, $locale = null, $softDelete = null
142
151
return $ query ;
143
152
}
144
153
145
- /**
146
- * Create new record.
147
- *
148
- * @param array $attributes
149
- */
150
- public static function create (array $ attributes )
151
- {
152
- $ model = new static ($ attributes );
153
-
154
- $ model ->save ($ attributes );
155
-
156
- return $ model ;
157
- }
158
-
159
154
/**
160
155
* Save record.
161
156
*
0 commit comments