Skip to content

Instantly share code, notes, and snippets.

View gravitano's full-sized avatar

Warsono gravitano

View GitHub Profile
@gravitano
gravitano / global.php
Created March 28, 2014 07:23
404 Error Handling on Laravel 4
App::missing(function()
{
if(Request::ajax())
{
return Response::json([
'code' => 404,
'message' => 'Sorry, that page does not exists.'
], 404);
}
return Response::view('404', [], 404);
@gravitano
gravitano / Creator.php
Last active August 29, 2015 13:57
Kelas sederhana untuk mempermudah proses validation saat pengimputan data atau update data.
<?php namespace Smile\Services\Creators;
use Illuminate\Validation\Factory as Validator;
abstract class Creator implements CreatorInterface
{
protected $model;
protected $errors;
@gravitano
gravitano / UsersController.php
Last active August 29, 2015 13:57
Kalo mau find data via Model/Eloquent, mending pake `findOrFail` aja, nanti tinggal di try and catch, ini contohnya.
<?php
use Illuminate\Database\Eloquent\ModelNotFoundException;
class UsersController extends Controller
{
/**
* Remove the specified resource from storage.
*
* @param int $id
@gravitano
gravitano / BaseRepository.php
Created March 29, 2014 04:30
Simple repository extended.
<?php namespace Smile\Repositories;
use App;
class BaseRepository
{
protected $model;
public function __construct()
{
# Initial setup
git clone -o framework -b develop https://github.com/laravel/laravel.git project-name
cd project-name
git checkout --orphan master
git commit -m "Initial commit"
# Pulling changes
git fetch framework
git merge --squash -m "Upgrade Laravel" framework/develop
# Fix merge conflicts if any and commit
@gravitano
gravitano / Twitter.php
Last active August 29, 2015 13:59
Simple Twitter API
<?php
class Twitter extends Eloquent
{
protected $fillable = ['id_str', 'name', 'username', 'avatar'];
}
@gravitano
gravitano / 404.blade.php
Created April 12, 2014 09:33
404 Not Found
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>404 Not Found</title>
<style>
@import url(//fonts.googleapis.com/css?family=Lato:700);
body {
margin:0;
@gravitano
gravitano / helpers.php
Last active August 29, 2015 13:59
My Helpers
<?php
// translator
function __($id, array $replace = array(), $locale = 'en')
{
return Lang::get('app.'.$id, $replace, $locale);
}
// file download
function set_download_header($filename)
<?php namespace Pingpong\Traits;
use Input, Redirect, Validator;
trait ValidatorTrait
{
protected $validator;
public function validate(array $input = null)
{
@gravitano
gravitano / flashes.blade.php
Created June 4, 2014 09:35
Flash Message !
@if(Session::has('flash_message'))
<div class="alert alert-{{ Session::get('flash_type', 'info') }} alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
{{ Session::get('flash_message') }}
</div>
@endif