When you validate an email in Laravel, you have the ability to specify whether you want a specific model to be excluded. The reason why you would exclude a model is for example, if you have a user account and the user needs to update their first name, but their email stays the same. Typically, Laravel would re-save the whole form and also validate the email, but because that user is already using the email, it will spit back a “unique” validation error mentioning the email already exists in the system (even though it is still being used by said user.
Download from Google Drive direct from cPanel server
I store cPanel backups on Google Drive and needed to restore a backup of a website which was 9GB.
Instead of downloading the file to my computer and re-uploading it to the server (which could take a considerable amount of time), I wanted to download the file straight from Google Drive to the server, this will download faster due to the connection of the server.
Unfortunately, a standard WGET does not work.
To do this, I went into Terminal for my cPanel server and downloaded pip:
Batch script to update WooCommerce product titles
I had a client who had named all of his 600+ products to uppercase and Google Shopping was not allowing the products to be indexed because of this.
To automatically rename the Woocommerce Product titles, I ran this script:
This will loop through each product and rename the titles to capitalised using php UCWORDS()
For example: MY PRODUCT will be renamed to My Product.
Vue2 Debounce with Lodash the right way
Accessing “this” within debounce only works if you use a standard function, not an arrow function. Eg.
search: _.debounce(function () { this.getData(); }, 500),
Create folder if doesn’t exist in Laravel
I needed to create a folder in Laravel /app folder if it didnt exist.
use Illuminate\Support\Facades\File; $folder = storage_path('app/myfolder'); // Ensure folder exists File::ensureDirectoryExists($folder);
This will ensure if a folder does not exist, it is created.
Add styles to WordPress Admin
I need to add some styles that only take effect in the WordPress Admin area, to do it, add this to functions.php
add_action('admin_head', 'my_custom_styles'); function my_custom_styles() { echo '<style> // Add styles here </style>'; }
Delete all ERROR_LOG files on WHM server
Log in to SSH, make sure you have admin rights
Run this command to list error_log files and their sizes
find /home -type f -iname error_log -exec du -sh {} \;
Want to delete them all? Run this:
find /home -type f -iname error_log -delete
Add featured image to admin table in WordPress for custom post type
On a project I’m doing, I created a custom post type for a catalogue and want the featured image to display on the admin table.
My custom post type is called “product” and I want to limit the feature to only the “product” custom post type. Here’s how I did it.
I added this into functions.php
Using / for division is deprecated and will be removed in Dart Sass 2.0.0 (FIXED)
Has an issue in NPM (specifically Laravel Mix) with my SASS files when compiling
To fix this, we need to do this
$ npm install -g sass-migrator $ sass-migrator division **/*.scss
Revert Laravel date format to YYYY-MM-DD H:i:s
Add this into the model
protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); }