1 year ago

How to create a Language Middleware for my Controller?

Posted 1 year ago by splendidkeen

Hey, I am repeatedly using this piece of logic:

if (auth()->user()->language_id == 1) {
             $language = 'en';
        } elseif (auth()->user()->language_id == 2) {
             $language = 'de';
        } else {
             $language = 'en';

to check on the language of choice from an authenticated user, with respect to related Carbon elements.

How can I create a Middleware out of this logic, so that I don't have to repeat it within every method?

Please sign in or create an account to participate in this conversation.