Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

faisal ahmed
faisal ahmed

Posted on • Originally published atMedium

Laravel subdomain specific locale

I needed to change the locale of one of my laravel based projects based on the subdomain. The setup was as follows -

I implemented the following inside AppServiceProvider to get the job done:

<?phpnamespace App\Providers;use Illuminate\Support\ServiceProvider;class AppServiceProvider extends ServiceProvider{    /**     * Register any application services.     */    public function register(): void    {        //    }    /**     * Bootstrap any application services.     */    public function boot(): void    {        //subdomain specific locale        $subdomain = current(explode('.', $_SERVER['HTTP_HOST']));        if (in_array($subdomain, ["www","fr","de"])) {            if($subdomain !== 'www'){                app()->setLocale($subdomain);                config('app.url',$subdomain.'.domain.com');            } else {                app()->setLocale('en');                config('app.url','www.domain.com');            }                    } else {            app()->setLocale('en');            config('app.url','www.domain.com');        }    }}
Enter fullscreen modeExit fullscreen mode

Hope this helps someone in future!

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I am a full stack web application developer from Dhaka, Bangladesh
  • Location
    Dhaka, Bangladesh
  • Work
    Full Stack Web Application Developer at Freelance
  • Joined

More fromfaisal ahmed

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp