Skip to content

Instantly share code, notes, and snippets.

View freekmurze's full-sized avatar

Freek Van der Herten freekmurze

View GitHub Profile
@reinink
reinink / webpack.mix.js
Created November 20, 2017 13:19
Using Purgecss with Tailwind and Laravel Mix
let cssImport = require('postcss-import')
let cssNext = require('postcss-cssnext')
let glob = require('glob-all')
let mix = require('laravel-mix')
let purgeCss = require('purgecss-webpack-plugin')
let tailwind = require('tailwindcss')
mix.js('resources/assets/js/app.js', 'public/js')
.postCss('resources/assets/css/app.css', 'public/css/app.css', [
cssImport(),
@brunogaspar
brunogaspar / macro.md
Last active September 15, 2024 18:42
Recursive Laravel Collection Macros

What?

If a nested array is passed into a Laravel Collection, by default these will be threaded as normal arrays.

However, that's not always the ideal case and it would be nice if we could have nested collections in a cleaner way.

This is where this macro comes in handy.

Setup

@mpociot
mpociot / FetchGitHubTotals.php
Last active November 6, 2024 14:28
GitHub component for the excellent Spatie dashboard package from https://github.com/spatie/dashboard.spatie.be
<?php
namespace App\Components\GitHub;
use App\Events\GitHub\FileContentFetched;
use App\Events\GitHub\TotalsFetched;
use GitHub;
use Illuminate\Console\Command;
class FetchGitHubTotals extends Command
@simonhamp
simonhamp / AppServiceProvider.php
Last active November 1, 2024 18:28
A pageable Collection implementation for Laravel
<?php
namespace App\Providers;
use Illuminate\Support\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
class AppServiceProvider extends ServiceProvider
{
public function boot()
<?php
/**
* Automatically alias Laravel Model's to their base classname.
* Ex: "App\Models\User" now can just be accessed by "User"
*/
if (! function_exists('aliasModels')) {
function aliasModels() {
$finder = new \Symfony\Component\Finder\Finder();
$finder->files()->name('*.php')->in(base_path().'/app');
@technoknol
technoknol / Enable CORS in Laravel 5.4.php
Created April 26, 2017 14:10
Enable CORS in laravel 5.4
<?php
# File: app\Http\Middleware\CORS.php
# Create file with below code in above location. And at the end of the file there are other instructions also.
# Please check.
namespace App\Http\Middleware;
use Closure;
class CORS {
@reinink
reinink / validation_macros.php
Created March 1, 2017 20:11
Laravel request validation macros
<?php
Request::macro('validate', function ($rules, $messages = [], $customAttributes = []) {
$this->lastValidated = array_keys($rules);
(new class() {
use ValidatesRequests;
})->validate($this, $rules, $messages, $customAttributes);
});
<?php
// Select all tables from the database
$tables = DB::select("SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname='public'");
// Get array of just the table names
$tables = array_column($tables, 'tablename');
// Loop through and drop each table
// The "cascade" option is important otherwise foreign keys constraints will fail
<?php
//yikes
class ArrayArrayObject extends ArrayObject
{
public function offsetSet($index, $value)
{
array_map(function ($k) use ($value) {
parent::offsetSet($k, $value);
}, (array)$index);
@gilbitron
gilbitron / InvoicePaid.php
Created November 14, 2016 12:31
Convert the Laravel Spark invoice email to a notification email
<?php // app/Notifications/InvoicePaid.php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Laravel\Cashier\Invoice;