Skip to content

Instantly share code, notes, and snippets.

@dedurus
dedurus / eloquent.md
Last active December 17, 2015 19:19 — forked from msurguy/eloquent.md

Conventions:

Defining Eloquent model (will assume that DB table named is set as plural of class name and primary key named "id"):

class Shop extends Eloquent {}

Using custom table name

protected $table = 'my_shops';

Awesome PHP

A curated list of amazingly awesome PHP libraries, resources and shiny things.

Composer

Composer Related

<?php
/*
* Dependency injection can help you reduce coupling and increase testability, making your applications more maintainable.
*
* DependencyResolver gives you the best of both worlds by mixing a registry with call time dependency resolution. In addition, it provides significant resource
* usage advantages over other patterns, such as an object pool, because dependencies are only resolved when they are actually needed.
*
* It supports both constructor injection for class wide dependencies, as well as method injection for method specific dependencies.
*
<?php
/**
* Return the coefficient of two items based on Jaccard index
* http://en.wikipedia.org/wiki/Jaccard_index
*
* Example:
*
* $tags1 = "code, php, jaccard, test, items";
* $tags2 = "test, code";

Sentry is an amazing auth system. But I really need a feature: multiple user types in the same app. And I cannot separate those in groups, because they have different table columns. After 2 days burning my head, I think I found a good solution. The magic is duplicate SentryServiceProvider with new different settings.

Lets suppose we have a fresh Sentry install with default User ambient. Now we want another ambient called Admin, with new model and different settings. How to do:

1. One model, one ambient

Let's create one model called Admin for our new ambient.

<?php
namespace Twilio;
use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\Collection;
use GuzzleHttp\Command\Guzzle\GuzzleClient;
use GuzzleHttp\Command\Guzzle\Description;
use GuzzleHttp\Command\Model;
use GuzzleHttp\Subscriber\Retry\RetrySubscriber;
<?php
class User extends Cartalyst\Sentry\Users\Eloquent\User {
/**
* @author Arda Kılıçdağı,
* @param $orderBy string how to order
* @param $sortBy string Sort like Ascending or Descending, values are asc/desc
* @param $toArray boolean whether to return the output as array or not. Default is false
*
<script type="text/javascript">
(function () {
"use strict";
// once cached, the css file is stored on the client forever unless
// the URL below is changed. Any change will invalidate the cache
var css_href = './index_files/web-fonts.css';
// a simple event handler wrapper
function on(el, ev, callback) {
if (el.addEventListener) {
el.addEventListener(ev, callback, false);
@dedurus
dedurus / Enhance.js
Created January 11, 2016 02:31 — forked from sebmarkbage/Enhance.js
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {