Skip to content

Instantly share code, notes, and snippets.

@Strernd
Created February 23, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Strernd/954a345aff1af4c96337 to your computer and use it in GitHub Desktop.
Save Strernd/954a345aff1af4c96337 to your computer and use it in GitHub Desktop.
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
abstract class CrudController extends Controller {
protected $model = null;
protected $viewDir = null;
protected $singular = null;
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
return view($this->viewDir.'.index',[$this->singular => $this->model->all()]);
}
...
}
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Banana;
use Illuminate\Http\Request;
class BananaController extends CrudController {
/**
* @param Banana $banana
*/
function __construct(Banana $banana) {
$this->singular = 'banana';
$this->model = $banana;
$this->viewDir = 'banana';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment