This file contains 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\Repositories; | |
/** | |
* RepositoryInterface provides the standard functions to be expected of ANY | |
* repository. | |
*/ | |
interface RepositoryInterface { | |
public function create(array $attributes); |
This file contains 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\Repositories; | |
use Acme\Abstracts\Repository as AbstractRepository; | |
class UserRepository extends AbstractRepository implements UserRepositoryInterface | |
{ | |
// This is where the "magic" comes from: | |
protected $modelClassName = 'User'; | |
// This class only implements methods specific to the UserRepository |
This file contains 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 | |
$repo = new Acme\Repositories\UserRepository; | |
// echo the name of the user with id 1 | |
echo $repo->find(1)->name; | |
// echo the number of users with username = johnsmith | |
echo count($repo->findByUsername('johnsmith')); |
This file contains 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', | |
)); |
This file contains 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 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 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 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 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 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', | |
OlderNewer