Skip to content

Instantly share code, notes, and snippets.

@paulund
paulund / google-webfont-async.php
Created Jul 14, 2018
Javascript tag to load google web font async
View google-webfont-async.php
<script type="text/javascript">
WebFontConfig = {
google: { families: [ 'Roboto' ] }
};
(function() {
var wf = document.createElement('script');
wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
'://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
@paulund
paulund / AppServiceProvider.php
Last active Aug 7, 2021
Laravel Cache Auth::user(). Learn how to cache the logged in user at https://paulund.co.uk/laravel-cache-authuser
View AppServiceProvider.php
<?php
namespace App\Providers;
use App\Models\User;
use App\Observers\UserObserver;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
View AuthTestsServiceProvider.php
<?php
namespace Dappa\AuthTests;
use Illuminate\Support\ServiceProvider;
/**
* Auth test service provider
*/
class AuthTestsServiceProvider extends ServiceProvider
@paulund
paulund / toggle.vue
Created Apr 15, 2018
How to create a VueJS toggle component
View toggle.vue
<template>
<div class="my-2">
<div class="toggle">
<input type="checkbox" :id="id" :name="id" value="1" v-on:change="updateValue($event.target.value)" :checked="isChecked" />
<label :for="id"></label>
</div>
<p class="inline-block">{{ label }}</p>
</div>
</template>
@paulund
paulund / AdminNewUser.php
Last active Mar 23, 2019
How to send an email to admin when new users sign up.
View AdminNewUser.php
<?php
namespace App\Mail;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class AdminNewUser extends Mailable
@paulund
paulund / www-redirect.conf
Created Apr 8, 2018
Nginx redirect www to non-www
View www-redirect.conf
server {
listen 80;
listen 443 ssl;
server_name www.example.com;
return 301 https://example.com$request_uri;
}
@paulund
paulund / laravel-recaptcha-validation.php
Created Apr 3, 2018
A Laravel validation rule to verify recaptcha.
View laravel-recaptcha-validation.php
<?php
namespace App\Rules;
use GuzzleHttp\Client;
use Illuminate\Contracts\Validation\Rule;
class GoogleRecaptcha implements Rule
{
/**
@paulund
paulund / PostController.php
Created Feb 10, 2018
A resource post controller example with tests.
View PostController.php
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Models\Post;
use Illuminate\Http\Request;
/**
* PostController
*/
@paulund
paulund / Results--html.vue
Created Dec 26, 2017
Creating a Laravel, VueJS, Algolia real time search results box.
View Results--html.vue
<template>
<section class="search-results" v-show="results.length > 0">
<div v-for="result in results" class="search-result">
<a :href="'/' + result.slug">{{ result.title }}</a>
</div>
</section>
</template>
@paulund
paulund / SmokeGuestTest.php
Last active Dec 17, 2017
Example of smoke testing guest URLs in a Laravel application
View SmokeGuestTest.php
<?php
namespace Tests\Feature\SmokeTests;
use App\Models\Post;
use App\Models\Tutorial;
use Illuminate\Routing\Router;
use Tests\TestCase;
class SmokeGuestTest extends TestCase