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

mvnobrega's avatar

Date format in multilingual site

The dates in the comment table follow the laravel's own timestamps pattern. That is, both created_at and updated_at are stored as follows: 2020-09-05 20:04:08

However, the site is multi-language, and I need to format the date according to the language directly on the controller. Look:

Controller Comments:

public function relatoUser(Request $request) {

            $comments = Comment::where('relato_id', $request->id)->paginate(10);
          
            return view('userRelato', compact('comments')); 
        
    }

My blade:

@foreach($comments as $c)

                <card-comment 
                created="{{ $comments->created_at->format('d/m/Y') }}">
                </card-comment>

@endforeach

But in this way, in all languages the graduate will appear in the Brazilian standard. Is there a way for me to determine this format still in the controller after checking the language that makes the request?

So I put just that {{ $comments->created_at }} and the date appears according to the user's language.

0 likes
5 replies
thewebartisan7's avatar

Try change locale using

        // Set carbon
        \Carbon\Carbon::setLocale($locale);

But is strange since that should be done by Laravel as I know

mvnobrega's avatar

but I need to define the format, because I don't want you to display the time

mvnobrega's avatar

I appreciate your help. Defining the model as you said seems like a good alternative too.

But I ended up choosing to define the format like this:

{{ $comments->created_at->format( __('dateformat')) }}">
thewebartisan7's avatar

I never think before something like that, but it's nice way to manage for multilanguage.

1 like

Please or to participate in this conversation.