Skip to content

Instantly share code, notes, and snippets.

View alexweissman's full-sized avatar
💭
For the glory of the swarm

Alex Weissman alexweissman

💭
For the glory of the swarm
View GitHub Profile
<?php
public function scopeUnionLike($query, $name, $value)
{
$columns = $this->getFillable();
if (!in_array($name, $columns)) {
throw new \PDOException("Column $name does not exist!");
}
$subQuery = $query->toSql();
@alexweissman
alexweissman / ApiController.php
Last active September 20, 2016 16:21
Example for sorting, searching, and paginating directly in the Eloquent query builder
<?php
/**
* Returns a list of workers.
*
* Generates a list of workers, optionally paginated, sorted and/or filtered.
* This page requires authentication.
* Request type: GET
*/
public function listWorkers()
@alexweissman
alexweissman / Worker.php
Created November 6, 2016 20:22
Represents a Worker and various helper scope queries
<?php
namespace UserFrosting;
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Worker Class
*
<?php
// suppose class FancyPost extends Post
// Do things using the Post class
$myPost = new Post();
Post::doSomething();
// Override
Post::mapClass('FancyPost');
@alexweissman
alexweissman / 1.0.0-dev.php
Created January 30, 2017 23:32
Basic migration for your sprinkle. Create in sprinkles/site/migrations/
<?php
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Schema\Blueprint;
/**
* Volunteer table
*/
if (!$schema->hasTable('volunteers')) {
$schema->create('volunteers', function (Blueprint $table) {
$table->increments('id');
<?php
namespace UserFrosting\Sprinkle\ExtendUser\Model;
use Illuminate\Database\Capsule\Manager as Capsule;
use UserFrosting\Sprinkle\Account\Model\User;
use UserFrosting\Sprinkle\ExtendUser\Model\Owler;
class OwlerUser extends User {
protected $fillable = [
@alexweissman
alexweissman / mycrap.html.twig
Last active March 28, 2017 22:10 — forked from abdullahseba/mycrap.twig
Abdullah's crap
{% extends "layouts/dashboard.html.twig" %}
{% block body_matter %}
<table>
<thead>
<th>From</th>
<th>Subject</th>
</thead>
<tbody id="email-messages-body"></tbody>
@alexweissman
alexweissman / uf-collection-2.js
Created May 10, 2017 23:03
Improvements to ufCollection
/**
* uf-collection plugin. Widget for attaching/detaching related items to a single parent item (e.g. roles for a user, etc).
*
* === USAGE ===
*
* uf-collection can be initialized on a div element as follows:
*
* $("#myCollection").ufCollection(options);
*
* `options` is an object containing any of the following parameters:
@alexweissman
alexweissman / BelongsToManyThrough.php
Last active May 12, 2023 07:58
Custom BelongsToManyThrough relationship for Laravel/Eloquent
<?php
/**
* UserFrosting (http://www.userfrosting.com)
*
* @link https://github.com/userfrosting/UserFrosting
* @copyright Copyright (c) 2013-2017 Alexander Weissman
* @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
*/
namespace UserFrosting\Sprinkle\Core\Model\Relations;
@alexweissman
alexweissman / example.js
Created August 9, 2017 17:46
Example setup for select2 with pagination and a Sprunjed endpoint
// Institution select
form.find("select[name='institutions[]']").select2({
ajax: {
url: site.uri.public + "/api/institutions",
dataType: "json",
delay: 250,
data: function (params) {
return {
filters: {
name : params.term