diff --git a/src/controllers/PermissionController.php b/src/controllers/PermissionController.php index 4f13569..b1c6cc3 100644 --- a/src/controllers/PermissionController.php +++ b/src/controllers/PermissionController.php @@ -1,7 +1,6 @@ fails()) { - $permission = new Permission(); + $permission = $this->createModel(); $permission->fill($attributes); $permission->save(); @@ -30,6 +31,18 @@ public function createPermission($attributes) return null; } + /** + * Create a new instance of the model. + * + * @return \Illuminate\Database\Eloquent\Model + */ + public function createModel() + { + $class = '\\'.ltrim($this->_model, '\\'); + + return new $class; + } + /** * Returns an all permissions. * @@ -37,9 +50,7 @@ public function createPermission($attributes) */ public function findAll() { - $model = new Permission(); - - return $model->newQuery()->get()->all(); + return $this->createModel()->newQuery()->get()->all(); } /** @@ -49,9 +60,7 @@ public function findAll() */ public function findById($id) { - $model = new Permission(); - - if(!$permission = $model->newQuery()->find($id)) + if(!$permission = $this->createModel()->newQuery()->find($id)) { throw new PermissionNotFoundException("A permission could not be found with ID [$id]."); } @@ -66,9 +75,7 @@ public function findById($id) */ public function findByValue($value) { - $model = new Permission(); - - if(!$permission = $model->newQuery()->where('value', $value)->get()->first()) + if(!$permission = $this->createModel()->newQuery()->where('value', $value)->get()->first()) { throw new PermissionNotFoundException("A permission could not be found with Value [$value]."); }