3
Within a index.blade.php
have a variable:
<td>{{$ordemjoin->dataplanejamento}}</td>
In the listing comes the date in the format English. How do I put in the format Brazilian?
Observing: version of Laravel 5.2
3
Within a index.blade.php
have a variable:
<td>{{$ordemjoin->dataplanejamento}}</td>
In the listing comes the date in the format English. How do I put in the format Brazilian?
Observing: version of Laravel 5.2
4
That should work:
<td>{{ date( 'd/m/Y' , strtotime($ordemjoin->dataplanejamento))}}</td>
Please avoid long discussions in the comments; your talk was moved to the chat
2
With class only use DB does not have all the features offered by Eloquent, so do it right on SQL
: DATE_FORMAT(dataplanejamento,'%d/%m/%Y') as dataplanejamentobr
DB::select("SELECT tabela.*,
DATE_FORMAT(dataplanejamento,'%d/%m/%Y') as dataplanejamentobr from tabela");
<td>{{$ordemjoin->dataplanejamentobr}}</td>
If you still don’t want to do so you can work with strtotime with date, but creates a helpers
and put a function to not keep repeating code:
function date_br($value, $format='d/m/Y')
{
return date($format, strtotime($value));
}
<td>{{date_br($carros->dataplanejamento)}}</td>
Recommending:
If you start using the Eloquent will realize the gain of programming in relation to using the class DB a clear example that I will illustrate would be the Date Mutators in class configuration, example:
In the array
of $dates
enter the field date
or datetime
in your case dataplanejamento
:
class Carros extends Model
{
protected $dates = [
'created_at',
'updated_at',
'deleted_at',
'dataplanejamento'
];
}
in his file of Views (blade
) could do straight like this:
<td>{{$carros->dataplanejamento->format('d/m/Y')}}</td>
it would be very easy and could format your date.
References:
0
Voce can use Casts passing in your model it returns the date in the correct format
protected $casts = [
'dataplanejamento' => 'datetime:d/m/Y',
];
0
Apparently by what you describe in the question and comments, the object must be a string. In this case the example below should solve:
{{Carbon\Carbon::parse($ordemjoin->dataplanejamento)->format('d/m/Y')}}
If the object is a Carbon
, just invoke the method format()
directly from the object itself.
{{$ordemjoin->dataplanejamento->format('d/m/Y')}}
Replace the line with this: {{Carbon Carbon::parse($ordemjoin->dataplanning)->format(’d/m/Y')}} Result: Brought nothing. Maybe Carbon is not installed. You have to know?
I’m using Vagrant ok?
Browser other questions tagged laravel laravel-blade
You are not signed in. Login or sign up in order to post.
the return of
$ordemjoin->dataplanejamento
is datetime?– RFL
you use the so
DB::select('select * from users where id = :id', ['id' => 1]);
to bring data???– novic
Yes I use DB. I still don’t know how eloquent works properly so I do the joins
– Marcos Birro
@Marcosbirro I made an answer by chance helped, or not?
– novic
It did. I’ll use the helpers.
– Marcos Birro
@Marcirro a question has some problem in the given answers that you do not accept as answers? I saw on your page that never gave
– novic
I accepted them all. I don’t see any that I didn’t answer They’re all helping me..
– Marcos Birro
Accept is to put blue check at the bottom of the arrow and score with a vote if you want. On your page are without.
– novic
Sure. It would be great.
– Marcos Birro
Truth @Marcosbirro if you can and want to read these link 1, link 2 and link 3
– novic