'', 'display_name' => '', 'first_name' => '', 'last_name' => '', 'user_email' => '', 'image' => '', 'user_login' => '', 'phone' => '', 'role' => [], 'status' => '', 'user_registered' => '', 'total_booking' => '', 'total_amount' => '', ]; /** * Display name attribute * * @param $customer * * @return string */ public function get_display_name_attribute( $customer ) { return $customer->first_name . ' ' . $customer->last_name; } /** * email attribute * * @param $customer * * @return string */ public function get_email_attribute( $customer ) { return $customer->email ?? $customer->user_email; } /** * total booking attribute * * @param $customer * * @return int */ public function get_total_booking_attribute( $customer ): int { $db = new Booktics_Database(); return ( new Order_Model( $db ) )->count( [ 'customer_id' => $customer->id ] ); } /** * Get total amount of all orders for a customer * * @param object $customer Customer object * * @return float Total amount of customer orders */ public function get_total_amount_attribute( $customer ) { $db = new Booktics_Database(); return ( new Order_Model( $db ) )->sum( 'total', [ 'customer_id' => $customer->id ] ); } }