Laravel only informs current date

Asked

Viewed 1,670 times

0

Hello, I’m informing on Construct of my entity the date as follows:

Entity:

public function __construct($fornecedor, $emissao, $vencimento)
{
    $this->fornecedor = $fornecedor;
    $this->emissao = new \DateTime();
    $this->vencimento = new \DateTime();
}

Form:

{!! Form::open(['url'=>'contas/salvar']) !!}

    {!! Form::label('fornecedor','Fornecedor') !!}
    {!! Form::input('number','fornecedor', null, ['class' => 'form-control','placeholder'=>'Fornecedor']) !!}<br />

    {!! Form::label('emissao','Data de Emissão') !!}
    {!! Form::input('date','emissao', null, ['class' => 'form-control']) !!}<br />

    {!! Form::label('vencimento','Data de Vencimento') !!}
    {!! Form::input('date','vencimento', null, ['class' => 'form-control']) !!}<br />

    {!! Form::submit('Salvar',['class'=>'btn btn-primary']) !!}

{!! Form::close() !!}

Controller:

public function salvar(Request $request, EM $em)
{
    $Controle = new Controle(
        $request->get('fornecedor'),
        $request->get('emissao'),
        $request->get("vencimento")
    );

    $em->persist($Controle );
    $em->flush();

    return redirect('controle');
}

But if I inform any date in my Form it ignores and records the current date. I have tried to put inside the Construct $this->emissao = date_create(date('Y m d')); but gives in the same. I just want to inform day month and year.

EDITION:

I put a $request->all() and a Print_r, returned me the following:

ModuloFinanceiro\Entities\Controle Object(

[fornecedor:ModuloFinanceiro\Entities\Controle:private] => Array
    (
        [_token] => IP5GwnGzUJW6TNsFeIyubFCNfKK7xoKhvgJuoIt1
        [fornecedor] => 1
        [emissao] => 2017-05-06
        [vencimento] => 2017-04-26
    )

[emissao:ModuloFinanceiro\Entities\Controle:private] => DateTime Object
    (
        [date] => 2017-04-20 14:47:27
        [timezone_type] => 3
        [timezone] => UTC
    )

[vencimento:ModuloFinanceiro\Entities\Controle:private] => DateTime Object
    (
        [date] => 2017-04-20 14:47:27
        [timezone_type] => 3
        [timezone] => UTC
    )
)
1

He is under writing?

  • You need to format the data sent by the form and use this string to instantiate the class DateTime within the function saĺvar

  • @Rafaelacioly Could you give me an example? I change the Construct for $this->emissao = date_create(date('Y m d')); and make which function change?

  • makes a $request->all() edits and asks the question? very strange what you are reporting...

  • @Virgilionovic edited and put the return. I had to put a $request for issuance and maturity also, if not, did not work...

  • Looks like he’s writing @Felipenunes ....

  • I don’t know how this is done in Doctrine because I use the Eloquent even in Laravel but, there is something related to that line: $Controle = new Controle( and why not work with Eloquent?

  • @Virgilionovic I use composite key in my bank... As soon as I find some solution, I post the answer.

Show 2 more comments

1 answer

0


Resolution:

Failed to pass as parameter $emissao and $vencimento inside new \DateTime();

public function __construct($fornecedor, $emissao, $vencimento)
{
    $this->fornecedor = $fornecedor;
    $this->emissao = new \DateTime($emissao);
    $this->vencimento = new \DateTime($vencimento);
}

Positive Result.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.