- https://speakerdeck.com/willroth/50-laravel-tricks-in-50-minutes
- https://www.reddit.com/r/laravel/comments/3to60i/50_laravel_tricks/
- 1. Automatic Model Validation
-- phpMyAdmin SQL Dump | |
-- version 4.5.1 | |
-- http://www.phpmyadmin.net | |
-- | |
-- Host: 127.0.0.1 | |
-- Generation Time: May 28, 2016 at 08:16 AM | |
-- Server version: 10.1.9-MariaDB | |
-- PHP Version: 5.6.15 | |
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; |
This file contains code snippets to be used while following the Angular 2 with Webpack Project Setup video tutorial.
You can find the full project in the angular2-course-webpack-starter repository.
<!DOCTYPE html>
<?php | |
function html_table($data = array()) | |
{ | |
$rows = array(); | |
foreach ($data as $row) { | |
$cells = array(); | |
foreach ($row as $cell) { | |
$cells[] = "<td>{$cell}</td>"; | |
} |
// 🔥 Node 7.6 has async/await! Here is a quick run down on how async/await works | |
const axios = require('axios'); // promised based requests - like fetch() | |
function getCoffee() { | |
return new Promise(resolve => { | |
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee | |
}); | |
} |
<?php namespace App\Exceptions; | |
use Log; | |
use Mail; | |
use Config; | |
use Exception; | |
use Illuminate\Auth\Access\UnauthorizedException; | |
use Illuminate\Session\TokenMismatchException; | |
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
// Custom Validator to add errors into vuex store and also handle laravel form errors. | |
import { mapGetters } from 'vuex'; | |
import { CLEAR_FORM_ERRORS, ERROR } from '../vuex/types'; | |
import Vue from 'vue'; | |
export default { | |
data() { | |
return { | |
errors: [], | |
keepServerErrors: ['unique', 'boolean', 'exists', 'regular_chars', 'identifier', 'date'], |
// Make sure to put this at the top of your AppServiceProvider: use Illuminate\Support\Facades\Validator; | |
Validator::extend('youtube', function ($attribute, $value, $parameters, $validator) { | |
preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $value, $matches); | |
return count($matches) > 0; | |
}, "Sorry, this doesn't look like a valid youtube URL"); |
Validator::extend('youtube', function ($attribute, $value, $parameters, $validator) { | |
return preg_match("/(youtube.com|youtu.be)\/(watch)?(\?v=)?(\S+)?/", $value); | |
}, "Sorry, this doesn't look like a valid youtube URL"); |
export const isSameURL = (a, b) => a.split('?')[0] === b.split('?')[0] | |
export const isRelativeURL = u => | |
u && u.length && /^\/[a-zA-Z0-9@\-%_~][/a-zA-Z0-9@\-%_~]*[?]?([^#]*)#?([^#]*)$/.test(u) | |
export default function ({ app }) { | |
const redirect = function (name, noRouter = false) { | |
if (!this.options.redirect) { | |
return | |
} |