@@ -276,10 +276,11 @@ function firstOrNewTranslation($attributes = null)
276276 && array_key_exists ('locale ' , $ attributes ) && array_key_exists ('key ' , $ attributes )
277277 && array_key_exists ($ attributes ['locale ' ], $ this ->preloadedGroupLocales )
278278 ) {
279+ $ checkDB = false ;
280+
279281 if (array_key_exists ($ attributes ['key ' ], $ this ->preloadedGroupKeys )
280282 && array_key_exists ($ attributes ['locale ' ], $ this ->preloadedGroupKeys [$ attributes ['key ' ]])
281283 ) {
282- $ checkDB = false ;
283284 $ translation = $ this ->preloadedGroupKeys [$ attributes ['key ' ]][$ attributes ['locale ' ]];
284285 }
285286 }
@@ -298,6 +299,9 @@ function firstOrNewTranslation($attributes = null)
298299 $ translation = new Translation ();
299300 $ translation ->fill ($ attributes );
300301 $ translation ->setConnection ($ this ->getConnectionName ());
302+
303+ // put it in the cache as empty so we don't hit the database every time
304+ $ this ->cacheTranslation ('' , $ translation ->group , $ translation ->key , null , $ translation ->locale );
301305 }
302306
303307 return $ translation ;
@@ -308,6 +312,9 @@ function firstOrCreateTranslation($attributes = null)
308312 $ translation = $ this ->firstOrNewTranslation ($ attributes );
309313 if (!$ translation ->exists ) {
310314 $ translation ->save ();
315+
316+ // put it in the cache as empty so we don't hit the database every time
317+ $ this ->cacheTranslation ('' , $ translation ->group , $ translation ->key , null , $ translation ->locale );
311318 }
312319
313320 return $ translation ;
0 commit comments