This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ... etc | |
// in bootstrap/start.php | |
$env = $app->detectEnvironment(array( | |
'local' => array('localhost'), | |
'staging' => array('staging.domain.org'), | |
'production' => array('domain.org'), | |
)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Response::macro('csv', function($data, $filename = 'data.csv', $status = 200, $delimiter = "|", $linebreak = "\n", $headers = array()) | |
{ | |
return Response::stream(function () use ($data, $delimiter, $linebreak) { | |
foreach ($data as $row) { | |
$keys = array(); $values = array(); | |
$i = (isset($i)) ? $i+1 : 0; | |
foreach ($row as $k => $v) { | |
if (!$i) $keys[] = is_string($k) ? '"' . str_replace('"', '""', $k) . '"' : $k; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace Acme\Controllers; | |
use Acme\Repositories\UserRepositoryInterface as UserRepository; | |
class UsersController extends \BaseController | |
{ | |
protected $userRepository; | |
public function __construct(UserRepository $userRepository) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ...etc | |
/* comment out the standard response registration */ | |
//'Response' => 'Illuminate\Support\Facades\Response', | |
/* add our new one...*/ | |
'Response' => 'Acme\Extensions\Facades\Response', | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// send back some HTML, rendered from a template | |
return Response::view('users.index', array( | |
'name' => 'Steve Brule', | |
'title' => 'Brule\'s Rules', | |
)); | |
// send back some json | |
return Response::json(array( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace Acme\Extensions\Facades; | |
class Response extends \Illuminate\Support\Facades\Response | |
{ | |
public static function csv($data, $filename = 'data.csv', $status = 200, $delimiter = "|", $linebreak = "\n", $headers = array()) | |
{ | |
return static::stream(function () use ($data, $delimiter, $linebreak) { | |
foreach ($data as $row) { | |
$keys = array(); $values = array(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* function to check whether a date is within the last 30 days | |
*/ | |
function withinOneMonth ($checkDate) { | |
$now = new DateTime(); | |
$thirtyDayInterval = new DateInterval('P30D'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* 00:00am (midnight) in Vietnam */ | |
$datetimeOne = new DateTime('2014-03-07 00:00:00+07:00'); | |
/* 04:00am in Australia */ | |
$datetimeTwo = new DateTime('2014-03-07 04:00:00+11:00'); | |
echo ($datetimeOne == $datetimeTwo) ? 'equal' : 'not equal'; | |
// prints 'equal' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// etc... | |
// find the payment if it already exists | |
$payment = Payment::where('txn_id', '=', Input::get('txn_id'))->get()->first(); | |
// if it doesn't exist, create the payment using all the fields in the POST | |
if (empty($payment)) $payment = Payment::create(Input::all()); | |
// if in debug mode, add the raw body of the request and also save it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// resolve the dependency | |
$repo = App::make('Acme\Repositories\ObjectRepository'); | |
// update the entity | |
$repo->update($object->id, array( | |
'attribute' => 'new value', | |
)); |