Hello there I need help in formatting my date before it reaches client side. Basically after getting the values from the database I want to format my date before it goes to the client side of my program like what I am doing here.
public function filterDataCal(Request $request) {
$filtered_table = Method::leftJoin('users', 'users.id', '=', 'methods.created_by')
->leftJoin('roles', 'roles.id', '=', 'users.role_id')
->leftJoin('types', 'types.id', '=', 'methods.type_id')
->where('type_id', '=', $request->filters['type_id'])
->get([ 'users.username', 'users.id AS users_id', 'methods.*', 'methods.id AS method_id', 'methods.name AS method_name', 'roles.id AS role_id', 'roles.name AS role_name',
'types.id AS type_id_typetable', 'types.name AS type_name']);
if($filtered_table) {
// for ($i=0; $i < sizeof($filtered_table); $i++){
//
// // foreach ($filtered_table as $value[i]) {
// // $value[i]->created_at->format("m/d/Y h:i A");
// // }
// }
foreach($filtered_table as $data) {
$data->created_at = $data->created_at->format('m/d/y h:i A');
}
return $filtered_table;
} else {
return "";
}
}
I was not sure what kind of syntax I need to do to change the format of the date I have gotten from the database so what I did was foreach
them then $data->created_at = $data->created_at->format('m/d/y h:i A');
but alas it won't go through, could you help me with changing that property (created_at) to a different format? Maybe I have something wrong with my syntax or maybe I there's a different approach. Thank you.