Skip to content

Instantly share code, notes, and snippets.

View rizqidjamaluddin's full-sized avatar

Rizqi Djamaluddin rizqidjamaluddin

  • Jakarta, Indonesia
View GitHub Profile
<?php
// you can do this from any code, anywhere in your codebase
$service = new CakeService;
$service->makeOrder("Bob", "Chocolate");
<?php
/**
* @test
*/
public function users_can_post_links_in_their_profile()
{
$mario = $this->registerAndLoginAsMario();
$set = $this->callJson('PUT', "/api/users/{$mario->hash}/profile", ['bio' => "A URL: http://www.google.com"]);
$fetch = $this->callJson('GET', "/api/users/{$mario->hash}/profile");
@rizqidjamaluddin
rizqidjamaluddin / ArticleRepository.php
Last active December 21, 2015 13:12
Generic Eloquent repository example
<?php
class ArticleRepository {
/**
* Because of how Eloquent works, an instance of a model is also a starting point to
* execute queries on it. This class should be instantiated by Laravel's IoC (e.g.
* constructor injection on a higher class, or App::make) so you never actually should
* need to do "new ArticleRepository(new Article)".
*
<?php namespace A\Parser;
use A\Parser\ParserDriver;
use Mews\Purifier\Purifier;
use Parsedown;
class ParsedownPurifierParserDriver implements ParserDriver
{
protected $trusted_settings = [
<?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();
<?php
class MailNotifier implements Notifier {
public function notify (Notification $n, Closure $next) {
Mail::send(); // ... whatever
return $next($n);
}
@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 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 / 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
use Illuminate\Console\Command;
class AddUncategorizedCategoryCommand extends Command
{
protected $name = 'appname:generate:categories';
protected $description = 'Generate default item categories.';
/**