Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Commit

Permalink
[Upg] add createModel method to service provider
Browse files Browse the repository at this point in the history
  • Loading branch information
MrJuliuss committed Sep 10, 2013
1 parent f1c32f0 commit 3c8e094
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
3 changes: 1 addition & 2 deletions src/controllers/PermissionController.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php namespace MrJuliuss\Syntara\Controllers;

use MrJuliuss\Syntara\Controllers\BaseController;
use MrJuliuss\Syntara\Models\Permissions\Permission;
use Paginator;
use PermissionProvider;
use View;
Expand All @@ -19,7 +18,7 @@ class PermissionController extends BaseController
*/
public function getIndex()
{
$permissions = new Permission;
$permissions = PermissionProvider::createModel();

$permissionId = Input::get('permissionIdSearch');
if(!empty($permissionId))
Expand Down
29 changes: 18 additions & 11 deletions src/models/Permissions/PermissionProvider.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php namespace MrJuliuss\Syntara\Models\Permissions;

use Illuminate\Support\Facades\Facade;
use MrJuliuss\Syntara\Models\Permissions\Permission;
use MrJuliuss\Syntara\Models\Permissions\PermissionNotFoundException;
use MrJuliuss\Syntara\Models\Permissions\PermissionExistsException;
use Validator;
use Config;

class PermissionProvider
{
protected $_model = 'MrJuliuss\Syntara\Models\Permissions\Permission';

/**
* Create permission
* @param array $attributes
Expand All @@ -20,7 +21,7 @@ public function createPermission($attributes)

if(!$validator->fails())
{
$permission = new Permission();
$permission = $this->createModel();
$permission->fill($attributes);
$permission->save();

Expand All @@ -30,16 +31,26 @@ 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.
*
* @return array
*/
public function findAll()
{
$model = new Permission();

return $model->newQuery()->get()->all();
return $this->createModel()->newQuery()->get()->all();
}

/**
Expand 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].");
}
Expand All @@ -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].");
}
Expand Down

0 comments on commit 3c8e094

Please sign in to comment.