Skip to content

Instantly share code, notes, and snippets.

View tournasdim's full-sized avatar
🎯
Focusing

Tournas Dimitrios tournasdim

🎯
Focusing
View GitHub Profile
@tournasdim
tournasdim / Gravatar.php
Created June 29, 2013 18:16
A Laravel Facade (Laravel 4)
<?php namespace Tournasdim\Getgravatar\Facades;
use Illuminate\Support\Facades\Facade;
class Gravatar extends Facade {
/**
* Get the registered name of the component.
*
* @return string
@tournasdim
tournasdim / GravatarServiceProvider.php
Created June 29, 2013 18:28
A Laravel ServiceProvider example (Laravel 4)
<?php namespace Tournasdim\Getgravatar;
use Illuminate\Support\ServiceProvider;
class GravatarServiceProvider extends ServiceProvider {
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
@tournasdim
tournasdim / BackboneJsTemplate.html
Created August 1, 2013 17:32
A BackBoneJS template (CDN links for required libraries)
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
@tournasdim
tournasdim / Authentication.php
Last active December 21, 2015 09:19
L4 Authentication example (into the route.php)
<?php
//Laravel 4 Validation example
Route::post('register', function() {
$rules = array(
'name' => 'required|min:3|max:80|alpha_dash',
'email' => 'required|between:3,64|email|unique:users',
'password' => 'required|alpha_num|between:4,8|confirmed',
'password_confirmation' => 'required|alpha_num|between:4,8'
);
@tournasdim
tournasdim / Authentication.php
Last active December 21, 2015 09:19
L4 Authentication signature (list of most used functions)
<?php
Route::post('login', function() {
// data from login form
//
$credentials = array(
'email' => Input::get('email'),
'password' => Input::get('password')
);
@tournasdim
tournasdim / Validation.php
Created August 20, 2013 17:35
L4 Validation examples (basic , how to define custom Validation rules )
<?php
/* Signature of a Validation */
$validator = Validator::make($data , $rules , $customMessage) ;
/* Validating submitted fields */
$inputs = Input::all();
$rules = array(
'name' => 'Required|max:100',
'email' => 'Required|email|max:100',
'msg' => 'Required|max:500'
@tournasdim
tournasdim / Cache.php
Created August 21, 2013 16:56
L4 Cache signature (list of most user methods)
<?php
Note that all items stored in the cache are serialized, so you are free to store any type of data
Cache::put('key', 'value', $minutes); // Storing An Item In The Cache
Cache::add('key', 'value', $minutes); // Storing An Item In The Cache If It Doesn't Exist
if (Cache::has('key')) { // } ; // Checking For Existence In Cache
$value = Cache::get('key'); // Retrieving a Cached value
$value = Cache::get('key', 'default'); // set a default value if key doesn't exists
$value = Cache::get('key', function() { return 'default'; }); // set a callback if the key doesn't exists
Cache::forever('key', 'value'); // storing a value permanently
Sometimes you may wish to retrieve an item from the cache, but also store a default value if the requested item doesn't exist :
@tournasdim
tournasdim / Cookies.php
Created August 22, 2013 10:03
L4 Cookies signature (list of most used methods)
<?php
Illuminate\Cookie\CookieJar.php : __construct(Request $request, Encrypter $encrypter)
Illuminate\Cookie\CookieServiceProvider
public function has($key) : Determine if a cookie exists and is not null.
public function get($key, $default = null)
public function make($name, $value, $minutes = 0, $path = null, $domain = null, $secure = false, $httpOnly = true)
public function forever($name, $value, $path = null, $domain = null, $secure = false, $httpOnly = true)
public function forget($name) // Expire the given cookie
public function setDefaultPathAndDomain($path, $domain)
public function getRequest()
@tournasdim
tournasdim / Session.php
Created August 22, 2013 10:35
L4 Session signature (list of most used Session methods)
<?php
Illuminate\Session\SessionServiceProvider --> Illuminate\Session\SessionManager -->
-----> Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage
Session::put('key', 'value'); // Storing An Item In The Session
Session::push('user.teams', 'developers'); // Push A Value Onto An Array Session Value
$value = Session::get('key'); // Retrieving An Item From The Session
$value = Session::get('key', 'default'); // Retrieving An Item Or Returning A Default Value
$value = Session::get('key', function() { return 'default'; }); // Retrieving An Item Or Returning A Default Value using a callback
$data = Session::all(); // Retrieving All Data From The Session
if (Session::has('users')) { //} ; // Determining If An Item Exists In The Session
@tournasdim
tournasdim / Migration_seeder.php
Created August 26, 2013 10:59
L4 Migration and seed example (a full example , from generating migration / seed files upto seeding to db with CLI)
<?php
php artisan migrate:make create_user_table
// app/database/migrations folder
<?php
use Illuminate\Database\Migrations\Migration;
class CreateUserTable extends Migration {
public function up()
{