Skip to content

Instantly share code, notes, and snippets.

@MartinTale
MartinTale / HasCompositePrimaryKeyTrait.php
Created December 18, 2019 02:10
Laravel trait to support composite primary keys in Eloquent models..
<?php
namespace App\Traits;
use Exception;
use Illuminate\Database\Eloquent\Builder;
trait HasCompositePrimaryKeyTrait
{
/**
@MartinTale
MartinTale / slugToHumanReadable.php
Created December 17, 2019 16:04
Converts slug to human readable string..
<?php
if (!function_exists('slugToHumanReadable')) {
function slugToHumanReadable($slug)
{
return ucwords(str_replace('-', ' ', $slug));
}
}
@MartinTale
MartinTale / numberWithSign.php
Created December 17, 2019 15:46
PHP function that converts number to a number with sign in front of it..
<?php
if (! function_exists('numberWithSign'))
{
function numberWithSign($number)
{
if ($number < 0) {
return round($number, 2);
} else {
return '+' . round($number, 2);
@MartinTale
MartinTale / isDate.php
Created December 17, 2019 15:44
PHP functions that validates that the given string is a date..
<?php
if (! function_exists('isDate'))
{
function isDate($string)
{
if (DateTime::createFromFormat('Y-m-d', trim($string)) !== FALSE) {
return true;
}
@MartinTale
MartinTale / hashTagToLink.php
Last active December 17, 2019 15:41
Laravel helper function that turn hashtags in a string into links..
@MartinTale
MartinTale / floatToTime.php
Last active December 17, 2019 15:37
PHP function that converts float number to time..
<?php
if (! function_exists('floatToTime')) {
function floatToTime($time, $long = false)
{
$minutes = fmod($time, 1) * 60;
$units = [
'm' => 'm',
'h' => 'h',
/**
* Escape special characters in the given string of html.
*
* @param {String} html
* @return {String}
*/
module.exports = {
escape: function(html) {
return String(html)
.replace(/&/g, '&amp;')
@MartinTale
MartinTale / webpack.config.js
Last active February 1, 2016 13:06
webpack.config.js
var webpack = require('webpack');
module.exports = {
debug: true,
entry: './src/index.js',
output: {
path: '.',
filename: "test-package.js"
},
module: {
@MartinTale
MartinTale / webpackBootstrap.js
Created February 1, 2016 13:03
webpackBootstrap
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
@MartinTale
MartinTale / gist:ec5773442b419044230e
Last active August 29, 2015 14:23
Multi Tenancy
<?php
// b/app/Tenant/Tenant.php
namespace Cms\Tenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;