0
Good morning, could someone help me with this formatting? Well, I have the following form:
<div class="form-group col-md-12 col-sm-12 col-xs-12">
<div class="col-md-2 col-sm-2 col-xs-2 form-label">
{{Form::label('date', 'Data')}}
</div>
<div class="col-md-3 col-sm-10 col-xs-10">
{{Form::date('date', null, ['class' => 'form-control'])}}
</div>
</div>
I have a query with a select picking the date field:
$query = DB::table('empenho as emp')
->select('emp.date as a')->orderby('emp.nrEmpenho');
Then I validate my form information:
if ($request->date) $query->where('emp.date', $request->date);
Everything works perfectly, but it returns me the field in this format:
I would like to return the field to me in Day/Month/Year, I thought that using Carbon:parse in the model would solve, but did not solve, I tried to do so in my model Commitment:
<?php
namespace Portal\Entity\Contabilidade;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;
class Empenho extends Model
{
protected $table = 'empenho';
public $timestamps = false;
public static $snakeAttributes = false;
protected $dates = ['date'];
public function getdateAttribute($value)
{
return Carbon::parse($value)->format('d/m/Y');
}
}
It doesn’t work and I don’t know what to do, could someone please help me? Anything that is not clear in the code let me know that I post any other necessary information, thank you !
Only
$value->format('d/m/Y');
doesn’t work?– rray
In fact it only works for a select in a form, when you click on the box it shows the selection formatted, but in the result the format returns to the form of the database. :/
– Lincoln Binda
If you change the input type to
text
the result is the same?– rray
But you mixed things up, it won’t work! The definition is in the model, but the select you are using
DB::table('tabela')
. As far as I know, that’s not right.– Wallace Maxters
Wallace, I use Carbon and format the field in the same model ! Even the form everything works perfectly, already in the filter goes back to normal format.
– Lincoln Binda
Which version of Laravel?
– gmsantos
5.1 ---- The friend downstairs helped me, thanks for the answers !
– Lincoln Binda
Helped but not the best way
– gmsantos
True, it is seen with "gambiarra", right, informed me, more at least it worked, if you know some way well seen could inform me?
– Lincoln Binda