public static function eventAuditLogger($target)
    {
        // exists flag is set on an existing record.
        if ($target->exists) {
            $message = 'UPDATE';
        } else {
            $message = 'INSERT';
        }

        // Fetch the currently logged in user
        $username = ApplogHelper::currentUserName();

        // Get the list of client IP addresses
        $clientIp = ApplogHelper::getClientIps();

        // Also get any addresses in _SERVER["HTTP_X_FORWARDED_FOR"]
        $forwardAddress = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
        if (empty($clientIp)) {
            $clientIp = $forwardAddress;
        } elseif (! empty($forwardAddress)) {
            $clientIp = $clientIp . ',' . $forwardAddress;
        }

        // Store the audit log.
        try {
            DB::table('applogs')->insert([
                'type'          => 'audit',
                'modelname'     => get_class($target),
                'foreign_id'    => $target->id,
                'classname'     => __CLASS__,
                'traitname'     => __TRAIT__,
                'functionname'  => __FUNCTION__,
                'filename'      => __FILE__,
                'linenumber'    => __LINE__,
                'message'       => $message,
                'details'       => $message . ' in ' . $target->getTable() . ' table.',
                'ipaddr'        => $clientIp,
                'created_by'    => $username,
                'updated_by'    => $username,
                'created_at'    => date('Y-m-d H:i:s'),
                'updated_at'    => date('Y-m-d H:i:s'),
            ]);
        } catch (\Exception $e) {
            // Do nothing
        }
    }
public static function eventAuditLogger($target)
    {
        // exists flag is set on an existing record.
        if ($target->exists) {
            $message = 'UPDATE';
        } else {
            $message = 'INSERT';
        }

        // Fetch the currently logged in user
        $username = ApplogHelper::currentUserName();

        // Get the list of client IP addresses
        $clientIp = ApplogHelper::getClientIps();

        // Also get any addresses in _SERVER["HTTP_X_FORWARDED_FOR"]
        $forwardAddress = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
        if (empty($clientIp)) {
            $clientIp = $forwardAddress;
        } elseif (! empty($forwardAddress)) {
            $clientIp = $clientIp . ',' . $forwardAddress;
        }

        // Store the audit log.
        try {
            DB::table('applogs')->insert([
                'type'          => 'audit',
                'modelname'     => get_class($target),
                'foreign_id'    => $target->id,
                'classname'     => __CLASS__,
                'traitname'     => __TRAIT__,
                'functionname'  => __FUNCTION__,
                'filename'      => __FILE__,
                'linenumber'    => __LINE__,
                'message'       => $message,
                'details'       => $message . ' in ' . $target->getTable() . ' table.',
                'ipaddr'        => $clientIp,
                'created_by'    => $username,
                'updated_by'    => $username,
                'created_at'    => date('Y-m-d H:i:s'),
                'updated_at'    => date('Y-m-d H:i:s'),
            ]);
        } catch (\Exception $e) {
            // Do nothing
        }
    }
public static function eventAuditLogger ( $ target ) { // exists flag is set on an existing record. if ( $ target -> exists ) { $ message = 'UPDATE' ; } else { $ message = 'INSERT' ; } // Fetch the currently logged in user $ username = ApplogHelper :: currentUserName ( ) ; // Get the list of client IP addresses $ clientIp = ApplogHelper :: getClientIps ( ) ; // Also get any addresses in _SERVER["HTTP_X_FORWARDED_FOR"] $ forwardAddress = isset ( $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] ) ? $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] : '' ; if ( empty ( $ clientIp ) ) { $ clientIp = $ forwardAddress ; } elseif ( ! empty ( $ forwardAddress ) ) { $ clientIp = $ clientIp . ',' . $ forwardAddress ; } // Store the audit log. try { DB :: table ( 'applogs' ) -> insert ( [ 'type' => 'audit' , 'modelname' => get_class ( $ target ) , 'foreign_id' => $ target -> id , 'classname' => __CLASS__ , 'traitname' => __TRAIT__ , 'functionname' => __FUNCTION__ , 'filename' => __FILE__ , 'linenumber' => __LINE__ , 'message' => $ message , 'details' => $ message . ' in ' . $ target -> getTable ( ) . ' table.' , 'ipaddr' => $ clientIp , 'created_by' => $ username , 'updated_by' => $ username , 'created_at' => date ( 'Y-m-d H:i:s' ) , 'updated_at' => date ( 'Y-m-d H:i:s' ) , ] ) ; } catch ( \ Exception $ e ) { // Do nothing } }
Generic audit logger.

This is set up as a listener for the after save event by the
bootAuditable method.

Store a message in the logs table in the database.
Use a raw query for this to prevent looping.

Just for the time being we are logging direct to a table rather
than going through the Monolog / Laravel logger API.

@param   Model   $target
@return  void
Generic audit logger .