I am trying to display posts for only 5 days after they are created. I have added $date->addDays(5)
to my controller, but nothing is showing in my blade. Here is my controller:
use Carbon\Carbon;
...
public function index(){
$date = Carbon::now();
$date->addDays(5);
$date->format("Y-m-d");
$posts = Post::where('status','=', 1)->whereDate('created_at','=', $date)->get();
return view('home', compact('date', $date))->with('posts', $posts);
}
...
And this is my home.blade.php
:
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">All posts
<a href="/posts/create" class="btn btn-primary" style="margin-left: 70%">New post +</a></div>
<hr>
<div class="card-body">
@foreach($posts as $post)
@if($post->status == 1)
<small style="color:red">PREMIUM POST</small>
<hr>
@endif
<h2>{{$post->name}}</h2><br>
<medium>{{$post->body}}</medium>
<hr style="border: 1.5px solid grey">
@endforeach
<small><?php echo now() ?></small>
</div>
</div>
</div>
</div>
</div>
@endsection
Why are my posts not being displayed in my blade? I am expecting them to show for 5 days after creation.