IT Daily Documentation

Remove duplicate after union two collections in Laravel 5

Problem: Having two collections/MySQL query results and combine them using union():


then want to remove all duplicate on that union result.

Solution: using unique() to remove duplicates. You can add a parameter like unique(‘id’) to specifically remove which tag name. Example:

$result1 = $result1->unique()->values()->all();

Remember to assign it to a variable or else it will remain the same.

Can’t access the website due to permission cause by SELinux

Problem: The folder permission all ready to set the appropriate one (744, etc). but still can not access some page, or some of the pages can not access due to permission denied.

Solution: use chcon -t httpd_sys_rw_content_t folder/ -R, replace folder/ with your folder

chcon -t httpd_sys_rw_content_t folder/ -R

Change localhost to correct domain path in Laravel

Problem: when resetting password or go to other routes, the path should no longer be a localhost but my new domain name. Still, the domain from URL is localhost.

Update .env file to update Laravel domain name

Solution: Update .env file, from APP_URL=http://localhost to APP_URL=

and remember to clean config setting by enter below command:

php artisan config:clear

Remove emoji function in WordPress

Problem: WordPress forced to add emoji function since version 4.2 and want to remove it.

Solution: In the theme folder that you are using, add below code to functions.php:

remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );

Auto-renew SSL certificate via letsencrypt in Cent OS 7

Problem: Want to auto-renew SSL cert via letsencrypt. I use letsencrypt-auto --apache -d to create SSL certificate.

Solution: first make letsencrypt program executable from anywhere since most of you just download a zip file from the Internet.

ln -s /opt/letsencrypt/letsencrypt-auto /usr/bin/letsencrypt 

then you can enter letsencrypt to trigger /opt/letsencrypt/letsencrypt-auto.

above command can eventually renew all certificates that about to expired.

Then add a record to cron job:

enter command crontab -e and add below content

0 0 * * 1 /usr/bin/letsencrypt  renew >> /var/log/le-renew.log

the command will trigger at 00:00 on every Monday. The renew record will save on /var/log/le-renew.log

Change WordPress index page content without affect the widget section.

Problem: Want to change WordPress index page content from post to page.

Solution: First go to /var/www/html/passive_income/wp-content/themes/twentyseventeen/index.php, follow below content

 * The main template file
 * This is the most generic template file in a WordPress theme
 * and one of the two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * E.g., it puts together the home page when no home.php file exists.
 * @link
 * @package WordPress
 * @subpackage Twenty_Seventeen
 * @since 1.0
 * @version 1.0

get_header(); ?>

<div class="wrap">
	<?php if ( is_home() && ! is_front_page() ) : ?>
		<header class="page-header">
			<h1 class="page-title"><?php single_post_title(); ?></h1>
	<?php else : ?>
	<header class="page-header">
		<h2 class="page-title"><?php _e( 'Posts', 'twentyseventeen' ); ?></h2>
	<?php endif; ?>

	<div id="primary" class="content-area">
		<main id="main" class="site-main" role="main">
			if ( have_posts() ) :

				/* Start the Loop */
			//	while ( have_posts() ) :
			//		the_post();

					 * Include the Post-Format-specific template for the content.
					 * If you want to override this in a child theme, then include a file
					 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
		 //	get_template_part( 'template-parts/post/content', get_post_format() );
	 $id = 1267;
 $post = get_page($id);
 $content = apply_filters('the_content', $post->post_content);
 echo $content;

			/*	the_posts_pagination(
						'prev_text'          => twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '<span class="screen-reader-text">' . __( 'Previous page', 'twentyseventeen' ) . '</span>',
						'next_text'          => '<span class="screen-reader-text">' . __( 'Next page', 'twentyseventeen' ) . '</span>' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ),
						'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyseventeen' ) . ' </span>',

			else :

				get_template_part( 'template-parts/post/content', 'none' );


		</main><!-- #main -->
	</div><!-- #primary -->
	<?php get_sidebar(); ?>
</div><!-- .wrap -->


keep in mind that the replace $id = 1267; 1267 is the page id.

Fatal error: Uncaught Error: Call to undefined function set_magic_quotes_runtime() in WordPress

Problem: When trying to import RSS via a built-in plugin, there is an error occurred Call to undefined function set_magic_quotes_runtime()

If you are using PHP 5.3 or after, set_magic_quotes_runtime() is already deprecated, although it will not cause a Fatal error it will send an E_DEPRECATED warning.

Solution: Remove all set_magic_quotes_runtime() in the WordPress project

Secured By miniOrange