Skip to content

Instantly share code, notes, and snippets.

View rizqidjamaluddin's full-sized avatar

Rizqi Djamaluddin rizqidjamaluddin

  • Jakarta, Indonesia
View GitHub Profile
<?php
class Notifier {
protected $from;
public function __construt($fromEmail) {
$this->from = $fromEmail;
}
<?php
class UserTest extends \IntegrationTest
{
/**
* @test
*/
public function users_cannot_self_register()
{
$response = $this->api('post', 'users/register', [
<?php
abstract class AbstractFactory {
public function getBindings() {
return [
Foo::class,
Bar::class
];
}
@rizqidjamaluddin
rizqidjamaluddin / CriteriaFactory.php
Created March 15, 2015 12:46
Factory/Criteria pattern with service provider bindings
<?php
class CriteriaFactory {
protected $transformations = [];
public function __construct(Array $t = []) {
$this->transformations = $t;
}
<?php
use Illuminate\Console\Command;
class AddUncategorizedCategoryCommand extends Command
{
protected $name = 'appname:generate:categories';
protected $description = 'Generate default item categories.';
/**
@rizqidjamaluddin
rizqidjamaluddin / rules.md
Last active August 29, 2015 14:16 — forked from machuga/rules.md

Asking for help in #laravel on Freenode

Please behave in a polite, considerate, and inclusive manner in the channel at all times. People volunteer their time in the channel to help people like you with your Laravel problems and some respect (in both directions) will go an extremely long way.

When asking questions in the #laravel channel, please follow these 12 simple rules.

  1. Do your research before hand. Your question may be answerable with a quick Google search or by simply experimenting. If it's a concept you're confused about, first check out our Official Documentation. If you're using a method in Laravel, you can look it up in the API Docs.
  2. If you've tried Googling, explain what terms you've tried to use so people can better help you.
  3. Clearly explain what is happening and create a Paste (http://laravel.io/bin), (http://kopy.io), or (http://gist.github.com) to better explain yourself
  4. **Do not use any paste service that is not [Lar
<?php
class License extends Model {
public static function generate (User $user) {
$i = new static;
$i->made_by = $user->id;
$i->serial = \Str::random(64); // you can also use a separate factory class that injects a random generator
$i->save();
}
@rizqidjamaluddin
rizqidjamaluddin / UserController.php
Last active August 29, 2015 14:15
Dead simple transformers
<?php
class UserController {
public function getUserForApi($id) {
return (new UserTransformer())->transform(User::find($id));
}
}
<?php
class MailNotifier implements Notifier {
public function notify (Notification $n, Closure $next) {
Mail::send(); // ... whatever
return $next($n);
}
<?php
use League\Csv\Reader;
class ImportCsvProjectCommand extends Command {
protected $name = 'import:users';
protected $genderAlias = ['M' => 'M', 'F' => 'F'];
public function fire() {
$data = Reader::createFromPath($this->argument('src'))->fetchAssoc();