File tree Expand file tree Collapse file tree 3 files changed +24
-2
lines changed
Http/Controllers/Operations Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ public function show($id)
7979 if ($ this ->crud ->get ('show.softDeletes ' ) && in_array ('Illuminate\Database\Eloquent\SoftDeletes ' , class_uses ($ this ->crud ->model ))) {
8080 $ this ->data ['entry ' ] = $ this ->crud ->getModel ()->withTrashed ()->findOrFail ($ id );
8181 } else {
82- $ this ->data ['entry ' ] = $ this ->crud ->getEntry ($ id );
82+ $ this ->data ['entry ' ] = $ this ->crud ->getEntryWithLocale ($ id );
8383 }
8484
8585 $ this ->data ['crud ' ] = $ this ->crud ;
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ public function edit($id)
6767 $ id = $ this ->crud ->getCurrentEntryId () ?? $ id ;
6868 $ this ->crud ->setOperationSetting ('fields ' , $ this ->crud ->getUpdateFields ());
6969 // get the info for that entry
70- $ this ->data ['entry ' ] = $ this ->crud ->getEntry ($ id );
70+ $ this ->data ['entry ' ] = $ this ->crud ->getEntryWithLocale ($ id );
7171 $ this ->data ['crud ' ] = $ this ->crud ;
7272 $ this ->data ['saveAction ' ] = $ this ->crud ->getSaveAction ();
7373 $ this ->data ['title ' ] = $ this ->crud ->getTitle () ?? trans ('backpack::crud.edit ' ).' ' .$ this ->crud ->entity_name ;
Original file line number Diff line number Diff line change @@ -64,6 +64,28 @@ public function getEntry($id)
6464 return $ this ->entry ;
6565 }
6666
67+ /**
68+ * Find and retrieve an entry in the database or fail.
69+ * When found, make sure we set the Locale on it.
70+ *
71+ * @param int The id of the row in the db to fetch.
72+ * @return \Illuminate\Database\Eloquent\Model The row in the db.
73+ */
74+ public function getEntryWithLocale ($ id )
75+ {
76+ if (! $ this ->entry ) {
77+ $ this ->entry = $ this ->getEntry ($ id );
78+ }
79+
80+ if ($ this ->entry ->translationEnabled ()) {
81+ $ locale = request ('_locale ' , \App::getLocale ());
82+ if (in_array ($ locale , array_keys ($ this ->entry ->getAvailableLocales ()))) {
83+ $ this ->entry ->setLocale ($ locale );
84+ }
85+ }
86+ return $ this ->entry ;
87+ }
88+
6789 /**
6890 * Return a Model builder instance with the current crud query applied.
6991 *
You can’t perform that action at this time.
0 commit comments