compare bank date with current date LARAVEL

Asked

Viewed 676 times

-2

How do I compare the date created_at with the current date and show the notes with that date

index php.

@if(\Carbon\Carbon::create($data)->format('d-m-Y') === \Carbon\Carbon::create($creat)->format('d-m-Y'))
    @foreach ($hoje as $hj)
     {{$hj>created_at}} //mostre os apontamentos de hoje
    @endforeach
@else
    teste
@endif

Controller

 $data = Carbon::today();
 $creat = Apontamento::get('created_at');
 $hoje = Apontamento::all();
  • So it’s very little information, there’s no way to answer!

  • @Virgilionovic but I didn’t understand ? i wanted to know how I compare two date, one of the bank and current date, I’m using the Carbon, but I’m not getting

  • 1

    Compare dates in PHP has several examples on the site, already searched ???

  • https://answall.com/questions/33469/como-comparar-datas-em-php an example!

  • yes.. I saw ai in index qe posted until in Function I used new data(), Datatime('NOW') and I could not...

  • 1

    'Cause there’s no rule there View ... you can send a status to your view if the date is met. As we do not know what to do gets complicated.

  • I saw that one, I tried to do it, but for Laravel.. I couldn’t... @Virgilionovic

  • Return view('home', Compact('client', 'pointing', 'aptFinalized', 'aptPendente', 'data', 'creat', 'today')); @Virgilionovic

  • First you have to learn PHP and then use Laravel. Because the Framework is done in PHP and with the database information you already have a comparison.

  • And what’s in your View cannot be compared like this, it needs to be the same as in this link: https://answall.com/questions/33469/howto comparedatas-em-php or even more here

  • @Virgilionovic I’ll take a look, but thank you

Show 6 more comments

1 answer

0

@Bruno, first of all compare these dates on controller and just pass to the view what you need already compared.

The way you are doing this screen can take quite a while to render, if you have 20,000 data, for example.

Then you should first filter the notes by the current date and then pass the variable already with the filtered data to the view

How to filter data in Laravel

For this you will use the Eloquent - Where Clauses making our lives a lot easier

Example:

$hoje = Apontamento::whereDate('created_at', today())->get();

The ->get() is to transform your Eloquent Builder in a Collection in order to process the data individually in your view

  • Thank you, I’ll take a look.

Browser other questions tagged

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