Skip to content

Commit

Permalink
Adjust user switch in LocalizationController
Browse files Browse the repository at this point in the history
The LocalizationController's user-switching method was amended to solve potential issues in updating user's locale. Instead of directly using the request's auth id method, the localized switch now uses \App\Models\User::find with the user's id from the request's method to ensure the right user is updated.
  • Loading branch information
Elshaden committed Dec 16, 2023
1 parent b67e019 commit 51d8ffa
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 34 deletions.
31 changes: 0 additions & 31 deletions .github/workflows/update-changelog.yml

This file was deleted.

5 changes: 4 additions & 1 deletion src/Http/LocalizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@

use App\Http\Controllers\Controller;

use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class LocalizationController extends Controller
{


public function changeLanguage(Request $request)
{
$User = \App\Models\User::find(auth()->id());
Log::info('LocalizationController:changeLanguage:User: '.$request->id.' :locale:'.$request->language);

$User = User::find($request->id);
$User->update( ['locale' => $request->language]);

return redirect()->to(config('app.url').config('nova.path'));
Expand Down
4 changes: 2 additions & 2 deletions src/NovaLocalizationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public function bootingPackage()

$language = app()->getLocale() == 'ar' ? 'en' : 'ar';

$menu->append(MenuItem::externalLink(app()->getLocale() == 'ar' ? 'English' : 'عربي', '/change-language/' . $language));
$menu->append(MenuItem::externalLink(app()->getLocale() == 'ar' ? 'English' : 'عربي', '/change-language/' . $language .'/' . $request->user()->id));

return $menu;
});

Route::get('change-language/{language}', [\Centrust\NovaLocalization\Http\LocalizationController::class, 'changeLanguage']);
Route::get('change-language/{language}/{id}', [\Centrust\NovaLocalization\Http\LocalizationController::class, 'changeLanguage']);
}
}

0 comments on commit 51d8ffa

Please sign in to comment.