Skip to content

Instantly share code, notes, and snippets.

@coreymcmahon
Created January 27, 2015 10:40
Show Gist options
  • Save coreymcmahon/9ddf1a8fb240a887f121 to your computer and use it in GitHub Desktop.
Save coreymcmahon/9ddf1a8fb240a887f121 to your computer and use it in GitHub Desktop.
ProductsController.php - A Pattern for Reusable Resource Controllers in Laravel 4.2 http://slashnode.com/reusable-resource-controllers/
<?php namespace App\Controllers\Admin;
use App\Controllers\BaseResourceController;
use App\Models\Products;
use App\Repositories\Products;
use App\Validators\Product as ProductValidator;
class ProductsController extends BaseResourceController
{
public function __construct(Product $model, Products $repo, ProductValidator $validator)
{
$this->model = $model;
$this->repo = $repo;
$this->validator = $validator;
}
/**
* @return string
*/
protected function userRole()
{
return 'admin';
}
/**
* @return string
*/
protected function resourceName()
{
return 'products';
}
/**
* @param null $entity_id
* @return array|void
*/
protected function formData($entity_id = null)
{
$categories = \App::make('App\Repositories\Categories')->all();
return [
'categories' => $categories
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment