File tree Expand file tree Collapse file tree 3 files changed +28
-4
lines changed
Http/Controllers/Operations Expand file tree Collapse file tree 3 files changed +28
-4
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 @@ -65,13 +65,14 @@ public function edit($id)
6565 $ this ->crud ->hasAccessOrFail ('update ' );
6666 // get entry ID from Request (makes sure its the last ID for nested resources)
6767 $ id = $ this ->crud ->getCurrentEntryId () ?? $ id ;
68- $ this ->crud ->setOperationSetting ('fields ' , $ this ->crud ->getUpdateFields ());
6968 // get the info for that entry
70- $ this ->data ['entry ' ] = $ this ->crud ->getEntry ($ id );
69+
70+ $ this ->data ['entry ' ] = $ this ->crud ->getEntryWithLocale ($ id );
71+ $ this ->crud ->setOperationSetting ('fields ' , $ this ->crud ->getUpdateFields ());
72+
7173 $ this ->data ['crud ' ] = $ this ->crud ;
7274 $ this ->data ['saveAction ' ] = $ this ->crud ->getSaveAction ();
7375 $ this ->data ['title ' ] = $ this ->crud ->getTitle () ?? trans ('backpack::crud.edit ' ).' ' .$ this ->crud ->entity_name ;
74-
7576 $ this ->data ['id ' ] = $ id ;
7677
7778 // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
Original file line number Diff line number Diff line change @@ -64,6 +64,29 @@ 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+
87+ return $ this ->entry ;
88+ }
89+
6790 /**
6891 * Return a Model builder instance with the current crud query applied.
6992 *
You can’t perform that action at this time.
0 commit comments