Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nmp4817's avatar

How to set up an application level attribute for API application?

Hi!

As we set up locale at the application level in Laravel.

How can I set up an application-level attribute (like a subdomain or mode)? (Which I am gonna get in each API request) but perhaps I can set it in middleware and can use it anywhere in an application for example Services or Repositories or Models ...

Thank you

0 likes
3 replies
tykus's avatar

You will find much of what you need here https://laravel.com/docs/8.x/localization

How you determine which locale to serve will depend on how your API user(s) request their locale - is it something that comes in the request via URI segment, or a header; or, does the authenticated user have a locale persisted (in the database for example).

nmp4817's avatar

Hi tykus

Thanks for responding. I was using localization as an example. I have already implemented localization but that was Laravel inbuilt feature. I want to set up some custom attributes like subdomain or mode.

with perhaps function like setSubdomain instead of setLocale.

Please or to participate in this conversation.