I am new at laravel and I want to show all yesterday previous messages in Earlier section from new section how can i do that ? please help me thanks.
Controller
public function index(){
$userNotificationIds = UserNotification::where('user_id',Auth::user()->id)->pluck('notification_id');
$data=[
'userNotification' => Notification::whereIn('id',$userNotificationIds)->orderBy('created_at','DESC')->paginate(8),
];
return view('web.user_notification',$data);
}
html view
<h4 >New</h4>
@if(count($userNotification) > 0)
@foreach ($userNotification as $value)
<div >
<div >
<img width="32px" height="32px" src="{{url('')}}/assets/web/img/profile-pic.png" alt="">
<div >
<span >Toby Ng</span>
<i class='bx bxs-circle small mx-2'></i>
<span >{{ $value->created_at->diffForHumans() }}</span>
<p ><span id="dots"> </span> {!! $value->description !!}</p>
<span onclick="myFunction()" id="myBtn">Read more</span>
</div>
</div>
</div>
@endforeach
@endif
{{ $userNotification->links() }}
<h4 >Earlier</h4>
<div >
<div >
<img width="32px" height="32px" src="img/avatar.png" alt="">
<div >
<span >Steven McNam</span>
<i class='bx bxs-circle small mx-2'></i>
<span >Yesterday</span>
<p >Welcome to WFH! Here is the link for you to get started. Please take your time to read it. <a href="#">https://www.google.com/</a></p>
</div>
</div>
</div>
CodePudding user response:
you can query for created_at less than or equal to yesterday
$earlier = Notification::whereIn('id',$userNotificationIds)->whereDate('created_at', '<=', \Illuminate\Support\Carbon::yesterday())->orderBy('created_at','DESC')->paginate(8)