Skip to content

Instantly share code, notes, and snippets.

@rtrudel
rtrudel / CustomBaseModel.php
Last active October 21, 2019 03:59
Makes Eloquent Model "save()" method returns NULL if nothing changed instead of TRUE (default behavior)
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
class CustomBaseModel extends Model {
// OVERRIDE: on update, if nothing changed, $saved is now NULL instead of TRUE.
@rtrudel
rtrudel / UniqueSlugs.php
Last active August 10, 2018 04:36
Craft CMS - Make slugs uniques across a specific section
<?php
// ADAPT THIS SOLUTION FOR YOUR NEEDS TO YOUR PLUGIN OR MODULE MAIN FILE, INSIDE THE "init()" METHOD
namespace something\something;
// make sure you have at least this in your "uses" declaration
use craft\elements\Entry;
use yii\base\Event;
use yii\base\ModelEvent;
@rtrudel
rtrudel / phpversion.sh
Created May 1, 2017 17:09
Switch PHP CLI version to 7.0 on Plesk
#!/bin/sh
printf "Switching php to version 7.0 with symlinks.\n"
printf "Press any key to continue...\n"
read CONTINUE
printf "Creating backups..."
# Backup original binaries
@rtrudel
rtrudel / craft-backup.sh
Last active November 10, 2016 04:32
Backup Craft CMS website to Google Drive
#!/bin/sh
# REQUIREMENTS
# gdrive - Google Drive CLI Client at https://github.com/prasmussen/gdrive
# cronjon creation ability
# GENERAL
#File prefix
PREFIX="backup-"