php - I'm trying to fetch rows based on the "created_at" field that are older than (for example) 30 days
I'm trying to fetch rows based on the created_at
field that are older than (for example) 30 days.
I'm using Laravel Eloquent. Can somebody help me with this?
I want to change the text in crud to be red here is my code
public function get_list_credit(Request $request)
{
$resultat=tbl_depot::whereEtatservi('Etatservi'== 0)
->orderBy('id','DESC')->get();
if('created_at' >= Carbon::now()){
}else{
}
return response()->json(['data'=>$resultat ]);
}
Answer
Solution:
You can use and
Carbon
to achieve this:
$result = tbl_depot::whereDate('created_at', '<', now()->subDays(30))->get();
Source