belongsTo( 'User' ); } public static function getComments( $foreignID, $tablename ) { $comments = Comment::orderBy( 'comment_date', 'desc' ) ->with( [ 'user' => function ( $q ) { $q->selectRaw( "CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname, id" ); }] ) ->whereForeignId( $foreignID ) ->whereForeignTable( $tablename ) ->get(); foreach ( $comments as $comment ) { $comment->comment = base64_decode( $comment->comment ); } return $comments; } public static function addComment( $foreignID, $tablename ) { $data = [ 'foreign_id' => $foreignID, 'foreign_table' => $tablename, 'user_id' => USERID, 'comment_date' => date( 'Y-m-d H:i:s' ) ]; $comment = Comment::create( $data ); return $comment['id']; } }