Skip to content

Instantly share code, notes, and snippets.

@ollieread
Last active August 29, 2015 14:05
Show Gist options
  • Save ollieread/84586f9cf7d44664b0c3 to your computer and use it in GitHub Desktop.
Save ollieread/84586f9cf7d44664b0c3 to your computer and use it in GitHub Desktop.
'Ollieread\Toolkit\ToolkitServiceProvider'
<?php namespace Ollieread\Toolkit\Repositories;
class BaseRepository
{
public function setModel($model);
public function setValidator($validator);
public function setContext($context);
public function make();
public function all($paginate = 0);
public function lists($value, $key = null, $select = false, $id = 0);
public function get($id);
public function getBy($field, $value);
public function create(array $data);
public function update($id, array $data);
public function delete($id);
public function with($with);
public function wipe();
}
"require": {
"ollieread/toolkit": "1.0.0"
}
<?php
return [
/*
* This is the path for your routes directory, it may be app/routes or it may be
* app/Project/Routes, whatever.
*/
'routes_directory' => app_path() . '/routes/',
/*
* Whether or not to use the default error handler for ValidationException, this
* will basically catch validation errors and redirect back with input and errors.
*
* Set to false if you wish to define your own.
*/
'catch_validation' => true,
/*
* Whether or not updates should be tidied up. This will basically go through the dat passed
* to BaseRepository::tidy($model, $data) and compare against the value in the model, anything
* that matches is stripped from the array.
*/
'pre_update_clean' => true,
/*
* Whether or not to remove empty values from an update, set to false if you wish to write empty values
* to your database.
*/
'pre_update_empty' => true
];
<?php
$repository->setContext($user->company->posts());
<?php
App::error(function (ValidationException $e) {
// Here we check the referer so that we don't get 'unable to redirect to empty url' errors.
$referer = Request::server('HTTP_REFERER');
if (!empty($referer)) {
// Send the input and the errors
return Redirect::back()->withInput()->withErrors($e->getErrors());
}
});
php artisan config:publish ollieread/toolkit
Route::file($prefix, $file[, $attributes]);
<?php
Route::file('/user', 'user.php', [
'namespace' => 'MyApp\Controllers\User',
'before' => 'auth'
]);
<?php
Route::get('/', [
'as' => 'user.index',
'uses' => 'UserController@index'
]);
Route::get('/{id}', [
'as' => 'user.show',
'uses' => 'UserController@show'
]);
<?php
use Ollieread\Toolkit\Validators\BaseValidator;
class MyValidator extends BaseValidator
{
public static $rules = [
'create' => [],
'update' => []
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment