Unverified Commit 0e316be3 authored by Viral Solani's avatar Viral Solani Committed by GitHub

Merge pull request #17 from bvipul/vs_master_trait_change

Added Model Master trait file and done related changes in each module
parents 893dae21 5ce27ecd
...@@ -17,8 +17,9 @@ trait AttributeClass ...@@ -17,8 +17,9 @@ trait AttributeClass
*/ */
public function getActionButtonsAttribute() public function getActionButtonsAttribute()
{ {
return '<div class="btn-group action-btn">'. return '<div class="btn-group action-btn">
//call your attribute functions here '.$this->getEditButtonAttribute(editPermission, editRoute).'
'</div>'; '.$this->getDeleteButtonAttribute(deletePermission, deleteRoute).'
</div>';
} }
} }
...@@ -2,14 +2,18 @@ ...@@ -2,14 +2,18 @@
namespace DummyNamespace; namespace DummyNamespace;
use App\Models\ModelTrait;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use DummyAttribute; use DummyAttribute;
use DummyRelationship; use DummyRelationship;
class DummyModel extends Model class DummyModel extends Model
{ {
use AttributeName, use ModelTrait,
RelationshipName; AttributeName,
RelationshipName {
// AttributeName::getEditButtonAttribute insteadof ModelTrait;
}
/** /**
* NOTE : If you want to implement Soft Deletes in this model, * NOTE : If you want to implement Soft Deletes in this model,
......
...@@ -45,6 +45,7 @@ class DummyRepoName extends BaseRepository ...@@ -45,6 +45,7 @@ class DummyRepoName extends BaseRepository
public function create(array $input) public function create(array $input)
{ {
$dummy_small_model_name = self::MODEL; $dummy_small_model_name = self::MODEL;
$dummy_small_model_name = new $dummy_small_model_name();
if ($dummy_small_model_name->save($input)) { if ($dummy_small_model_name->save($input)) {
return true; return true;
} }
......
...@@ -106,6 +106,22 @@ class Generator ...@@ -106,6 +106,22 @@ class Generator
protected $update_permission; protected $update_permission;
protected $delete_permission; protected $delete_permission;
/**
* Routes
* 1. Edit Route
* 2. Store Route
* 3. Manage Route
* 4. Create Route
* 5. Update Route
* 6. Delete Route.
*/
protected $edit_route;
protected $store_route;
protected $index_route;
protected $create_route;
protected $update_route;
protected $delete_route;
/** /**
* Repository * Repository
* 1. Repository Name * 1. Repository Name
...@@ -206,6 +222,14 @@ class Generator ...@@ -206,6 +222,14 @@ class Generator
$this->update_permission = 'update-'.strtolower(str_singular($this->model)); $this->update_permission = 'update-'.strtolower(str_singular($this->model));
$this->delete_permission = 'delete-'.strtolower(str_singular($this->model)); $this->delete_permission = 'delete-'.strtolower(str_singular($this->model));
//Routes
$this->index_route = 'admin.'.strtolower(str_plural($this->model)).'.index';
$this->create_route = 'admin.'.strtolower(str_plural($this->model)).'.create';
$this->store_route = 'admin.'.strtolower(str_plural($this->model)).'.store';
$this->edit_route = 'admin.'.strtolower(str_plural($this->model)).'.edit';
$this->update_route = 'admin.'.strtolower(str_plural($this->model)).'.update';
$this->delete_route = 'admin.'.strtolower(str_plural($this->model)).'.destroy';
//Events //Events
$this->events = array_filter($input['event']); $this->events = array_filter($input['event']);
...@@ -342,11 +366,15 @@ class Generator ...@@ -342,11 +366,15 @@ class Generator
*/ */
public function createModel() public function createModel()
{ {
$this->createDirectory($this->getBasePath($this->attribute_namespace)); $this->createDirectory($this->getBasePath($this->removeFileNameFromEndOfNamespace($this->attribute_namespace)));
//Generate Attribute File //Generate Attribute File
$this->generateFile('Attribute', [ $this->generateFile('Attribute', [
'AttributeNamespace' => ucfirst($this->removeFileNameFromEndOfNamespace($this->attribute_namespace)), 'AttributeNamespace' => ucfirst($this->removeFileNameFromEndOfNamespace($this->attribute_namespace)),
'AttributeClass' => $this->attribute, 'AttributeClass' => $this->attribute,
'editPermission' => $this->edit_permission,
'editRoute' => $this->edit_route,
'deletePermission' => $this->delete_permission,
'deleteRoute' => $this->delete_route
], lcfirst($this->attribute_namespace)); ], lcfirst($this->attribute_namespace));
//Generate Relationship File //Generate Relationship File
......
...@@ -2,17 +2,23 @@ ...@@ -2,17 +2,23 @@
namespace App\Models\Access\Permission; namespace App\Models\Access\Permission;
use App\Models\Access\Permission\Traits\Attribute\PermissionAttribute; use App\Models\ModelTrait;
use App\Models\Access\Permission\Traits\Relationship\PermissionRelationship;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\Access\Permission\Traits\Attribute\PermissionAttribute;
use App\Models\Access\Permission\Traits\Relationship\PermissionRelationship;
/** /**
* Class Permission. * Class Permission.
*/ */
class Permission extends Model class Permission extends Model
{ {
use PermissionRelationship, PermissionAttribute, SoftDeletes; use ModelTrait,
SoftDeletes,
PermissionAttribute,
PermissionRelationship {
// PermissionAttribute::getEditButtonAttribute insteadof ModelTrait;
}
/** /**
* The database table used by the model. * The database table used by the model.
......
...@@ -7,42 +7,14 @@ namespace App\Models\Access\Permission\Traits\Attribute; ...@@ -7,42 +7,14 @@ namespace App\Models\Access\Permission\Traits\Attribute;
*/ */
trait PermissionAttribute trait PermissionAttribute
{ {
/**
* @return string
*/
public function getEditButtonAttribute()
{
if (access()->allow('edit-permission')) {
return '<a class="btn btn-flat btn-default" href="'.route('admin.access.permission.edit', $this).'">
<i data-toggle="tooltip" data-placement="top" title="Edit" class="fa fa-pencil"></i>
</a>';
}
}
/**
* @return string
*/
public function getDeleteButtonAttribute()
{
if (access()->allow('delete-permission')) {
return '<a class="btn btn-flat btn-default" href="'.route('admin.access.permission.destroy', $this).'" data-method="delete"
data-trans-button-cancel="'.trans('buttons.general.cancel').'"
data-trans-button-confirm="'.trans('buttons.general.crud.delete').'"
data-trans-title="'.trans('strings.backend.general.are_you_sure').'">
<i data-toggle="tooltip" data-placement="top" title="Delete" class="fa fa-trash"></i>
</a>';
}
}
/** /**
* @return string * @return string
*/ */
public function getActionButtonsAttribute() public function getActionButtonsAttribute()
{ {
return '<div class="btn-group action-btn"> return '<div class="btn-group action-btn">
'.$this->getEditButtonAttribute().' '.$this->getEditButtonAttribute('edit-permission', 'admin.access.permission.edit').'
'.$this->getDeleteButtonAttribute().' '.$this->getDeleteButtonAttribute('delete-permission', 'admin.access.permission.destroy').'
</div>'; </div>';
} }
} }
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
namespace App\Models\Access\Role; namespace App\Models\Access\Role;
use App\Models\Access\Role\Traits\Attribute\RoleAttribute; use App\Models\ModelTrait;
use App\Models\Access\Role\Traits\Relationship\RoleRelationship;
use App\Models\Access\Role\Traits\RoleAccess;
use App\Models\Access\Role\Traits\Scope\RoleScope;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\Access\Role\Traits\RoleAccess;
use App\Models\Access\Role\Traits\Scope\RoleScope;
use App\Models\Access\Role\Traits\Attribute\RoleAttribute;
use App\Models\Access\Role\Traits\Relationship\RoleRelationship;
/** /**
* Class Role. * Class Role.
...@@ -15,10 +16,14 @@ use Illuminate\Database\Eloquent\SoftDeletes; ...@@ -15,10 +16,14 @@ use Illuminate\Database\Eloquent\SoftDeletes;
class Role extends Model class Role extends Model
{ {
use RoleScope, use RoleScope,
ModelTrait,
RoleAccess, RoleAccess,
RoleAttribute, RoleAttribute,
RoleRelationship, RoleRelationship,
SoftDeletes; SoftDeletes {
RoleAttribute::getEditButtonAttribute insteadof ModelTrait;
RoleAttribute::getDeleteButtonAttribute insteadof ModelTrait;
}
/** /**
* The database table used by the model. * The database table used by the model.
......
...@@ -43,7 +43,7 @@ trait RoleAttribute ...@@ -43,7 +43,7 @@ trait RoleAttribute
public function getActionButtonsAttribute() public function getActionButtonsAttribute()
{ {
return '<div class="btn-group action-btn"> return '<div class="btn-group action-btn">
'.$this->getEditButtonAttribute().' '.$this->getEditButtonAttribute('edit-role', 'admin.access.role.edit').'
'.$this->getDeleteButtonAttribute().' '.$this->getDeleteButtonAttribute().'
</div>'; </div>';
} }
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
namespace App\Models\Access\User; namespace App\Models\Access\User;
use App\Models\Access\User\Traits\Attribute\UserAttribute; use Illuminate\Notifications\Notifiable;
use App\Models\Access\User\Traits\Relationship\UserRelationship;
use App\Models\Access\User\Traits\Scope\UserScope;
use App\Models\Access\User\Traits\UserAccess;
use App\Models\Access\User\Traits\UserSendPasswordReset;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\Access\User\Traits\UserAccess;
use App\Models\Access\User\Traits\Scope\UserScope;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable; use App\Models\Access\User\Traits\UserSendPasswordReset;
use App\Models\Access\User\Traits\Attribute\UserAttribute;
use App\Models\Access\User\Traits\Relationship\UserRelationship;
/** /**
* Class User. * Class User.
......
...@@ -2,16 +2,20 @@ ...@@ -2,16 +2,20 @@
namespace App\Models\BlogCategories; namespace App\Models\BlogCategories;
use App\Models\BlogCategories\Traits\Attribute\BlogCategoryAttribute; use App\Models\ModelTrait;
use App\Models\BlogCategories\Traits\Relationship\BlogCategoryRelationship;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\BlogCategories\Traits\Attribute\BlogCategoryAttribute;
use App\Models\BlogCategories\Traits\Relationship\BlogCategoryRelationship;
class BlogCategory extends Model class BlogCategory extends Model
{ {
use BlogCategoryAttribute, use ModelTrait,
SoftDeletes, SoftDeletes,
BlogCategoryRelationship; BlogCategoryAttribute,
BlogCategoryRelationship {
// BlogCategoryAttribute::getEditButtonAttribute insteadof ModelTrait;
}
/** /**
* The database table used by the model. * The database table used by the model.
......
...@@ -7,41 +7,14 @@ namespace App\Models\BlogCategories\Traits\Attribute; ...@@ -7,41 +7,14 @@ namespace App\Models\BlogCategories\Traits\Attribute;
*/ */
trait BlogCategoryAttribute trait BlogCategoryAttribute
{ {
/**
* @return string
*/
public function getEditButtonAttribute()
{
if (access()->allow('edit-blog-category')) {
return '<a class="btn btn-flat btn-default" href="'.route('admin.blogcategories.edit', $this).'">
<i data-toggle="tooltip" data-placement="top" title="'.trans('buttons.general.crud.edit').'" class="fa fa-pencil"></i>
</a>';
}
}
/**
* @return string
*/
public function getDeleteButtonAttribute()
{
if (access()->allow('delete-blog-category')) {
return '<a class="btn btn-flat btn-default" href="'.route('admin.blogcategories.destroy', $this).'" data-method="delete"
data-trans-button-cancel="'.trans('buttons.general.cancel').'"
data-trans-button-confirm="'.trans('buttons.general.crud.delete').'"
data-trans-title="'.trans('strings.backend.general.are_you_sure').'">
<i data-toggle="tooltip" data-placement="top" title="Delete" class="fa fa-trash"></i>
</a>';
}
}
/** /**
* @return string * @return string
*/ */
public function getActionButtonsAttribute() public function getActionButtonsAttribute()
{ {
return '<div class="btn-group action-btn"> return '<div class="btn-group action-btn">
'.$this->getEditButtonAttribute().' '.$this->getEditButtonAttribute('edit-blog-category', 'admin.blogcategories.edit').'
'.$this->getDeleteButtonAttribute().' '.$this->getDeleteButtonAttribute('delete-blog-category', 'admin.blogcategories.destroy').'
</div>'; </div>';
} }
} }
...@@ -2,16 +2,20 @@ ...@@ -2,16 +2,20 @@
namespace App\Models\BlogTags; namespace App\Models\BlogTags;
use App\Models\BlogTags\Traits\Attribute\BlogTagAttribute; use App\Models\ModelTrait;
use App\Models\BlogTags\Traits\Relationship\BlogTagRelationship;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\BlogTags\Traits\Attribute\BlogTagAttribute;
use App\Models\BlogTags\Traits\Relationship\BlogTagRelationship;
class BlogTag extends Model class BlogTag extends Model
{ {
use BlogTagAttribute, use ModelTrait,
SoftDeletes, SoftDeletes,
BlogTagRelationship; BlogTagAttribute,
BlogTagRelationship{
// BlogTagAttribute::getEditButtonAttribute insteadof ModelTrait;
}
/** /**
* The database table used by the model. * The database table used by the model.
......
...@@ -7,41 +7,14 @@ namespace App\Models\BlogTags\Traits\Attribute; ...@@ -7,41 +7,14 @@ namespace App\Models\BlogTags\Traits\Attribute;
*/ */
trait BlogTagAttribute trait BlogTagAttribute
{ {
/**
* @return string
*/
public function getEditButtonAttribute()
{
if (access()->allow('edit-blog-tag')) {
return '<a class="btn btn-flat btn-default" href="'.route('admin.blogtags.edit', $this).'">
<i data-toggle="tooltip" data-placement="top" title="'.trans('buttons.general.crud.edit').'" class="fa fa-pencil"></i>
</a>';
}
}
/**
* @return string
*/
public function getDeleteButtonAttribute()
{
if (access()->allow('delete-blog-tag')) {
return '<a class="btn btn-flat btn-default" href="'.route('admin.blogtags.destroy', $this).'" data-method="delete"
data-trans-button-cancel="'.trans('buttons.general.cancel').'"
data-trans-button-confirm="'.trans('buttons.general.crud.delete').'"
data-trans-title="'.trans('strings.backend.general.are_you_sure').'">
<i data-toggle="tooltip" data-placement="top" title="'.trans('buttons.general.crud.delete').'" class="fa fa-trash"></i>
</a>';
}
}
/** /**
* @return string * @return string
*/ */
public function getActionButtonsAttribute() public function getActionButtonsAttribute()
{ {
return '<div class="btn-group action-btn"> return '<div class="btn-group action-btn">
'.$this->getEditButtonAttribute().' '.$this->getEditButtonAttribute('edit-blog-tag', 'admin.blogtags.edit').'
'.$this->getDeleteButtonAttribute().' '.$this->getDeleteButtonAttribute('delete-blog-tag', 'admin.blogtags.destroy').'
</div>'; </div>';
} }
} }
...@@ -2,16 +2,20 @@ ...@@ -2,16 +2,20 @@
namespace App\Models\Blogs; namespace App\Models\Blogs;
use App\Models\Blogs\Traits\Attribute\BlogAttribute; use App\Models\ModelTrait;
use App\Models\Blogs\Traits\Relationship\BlogRelationship;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\Blogs\Traits\Attribute\BlogAttribute;
use App\Models\Blogs\Traits\Relationship\BlogRelationship;
class Blog extends Model class Blog extends Model
{ {
use BlogAttribute, use ModelTrait,
BlogRelationship, SoftDeletes,
SoftDeletes; BlogAttribute,
BlogRelationship {
// BlogAttribute::getEditButtonAttribute insteadof ModelTrait;
}
/** /**
* The database table used by the model. * The database table used by the model.
......
...@@ -7,42 +7,14 @@ namespace App\Models\Blogs\Traits\Attribute; ...@@ -7,42 +7,14 @@ namespace App\Models\Blogs\Traits\Attribute;
*/ */
trait BlogAttribute trait BlogAttribute
{ {
/**
* @return string
*/
public function getEditButtonAttribute()
{
if (access()->allow('edit-blog')) {
return '<a href="'.route('admin.blogs.edit', $this).'" class="btn btn-flat btn-default">
<i data-toggle="tooltip" data-placement="top" title="Edit" class="fa fa-pencil"></i>
</a>';
}
}
/**
* @return string
*/
public function getDeleteButtonAttribute()
{
if (access()->allow('delete-blog')) {
return '<a href="'.route('admin.blogs.destroy', $this).'"
class="btn btn-flat btn-default" data-method="delete"
data-trans-button-cancel="'.trans('buttons.general.cancel').'"
data-trans-button-confirm="'.trans('buttons.general.crud.delete').'"
data-trans-title="'.trans('strings.backend.general.are_you_sure').'">
<i data-toggle="tooltip" data-placement="top" title="Delete" class="fa fa-trash"></i>
</a>';
}
}
/** /**
* @return string * @return string
*/ */
public function getActionButtonsAttribute() public function getActionButtonsAttribute()
{ {
return '<div class="btn-group action-btn">'. return '<div class="btn-group action-btn">'.
$this->getEditButtonAttribute(). $this->getEditButtonAttribute('edit-blog', 'admin.blogs.edit').
$this->getDeleteButtonAttribute(). $this->getDeleteButtonAttribute('delete-blog', 'admin.blogs.destroy').
'</div>'; '</div>';
} }
} }
...@@ -2,14 +2,18 @@ ...@@ -2,14 +2,18 @@
namespace App\Models\CMSPages; namespace App\Models\CMSPages;
use App\Models\CMSPages\Traits\Attribute\CMSPageAttribute; use App\Models\ModelTrait;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\CMSPages\Traits\Attribute\CMSPageAttribute;
class CMSPage extends Model class CMSPage extends Model
{ {
use CMSPageAttribute, use ModelTrait,
SoftDeletes; SoftDeletes,
CMSPageAttribute {
// CMSPageAttribute::getEditButtonAttribute insteadof ModelTrait;
}
/** /**
* The database table used by the model. * The database table used by the model.
......
...@@ -7,41 +7,14 @@ namespace App\Models\CMSPages\Traits\Attribute; ...@@ -7,41 +7,14 @@ namespace App\Models\CMSPages\Traits\Attribute;
*/ */
trait CMSPageAttribute trait CMSPageAttribute
{ {
/**
* @return string
*/
public function getEditButtonAttribute()
{
if (access()->allow('edit-cms-pages')) {
return '<a class="btn btn-flat btn-default" href="'.route('admin.cmspages.edit', $this).'">
<i data-toggle="tooltip" data-placement="top" title="'.trans('buttons.general.crud.edit').'" class="fa fa-pencil"></i>
</a>';
}
}
/**
* @return string
*/
public function getDeleteButtonAttribute()
{
if (access()->allow('delete-cms-pages')) {
return '<a class="btn btn-flat btn-default" href="'.route('admin.cmspages.destroy', $this).'" data-method="delete"
data-trans-button-cancel="'.trans('buttons.general.cancel').'"
data-trans-button-confirm="'.trans('buttons.general.crud.delete').'"
data-trans-title="'.trans('strings.backend.general.are_you_sure').'">
<i data-toggle="tooltip" data-placement="top" title="Delete" class="fa fa-trash"></i>
</a>';
}
}
/** /**
* @return string * @return string
*/ */
public function getActionButtonsAttribute() public function getActionButtonsAttribute()
{ {
return '<div class="btn-group action-btn"> return '<div class="btn-group action-btn">
'.$this->getEditButtonAttribute().' '.$this->getEditButtonAttribute('edit-cms-pages', 'admin.cmspages.edit').'
'.$this->getDeleteButtonAttribute().' '.$this->getDeleteButtonAttribute('delete-cms-pages', 'admin.cmspages.destroy').'
</div>'; </div>';
} }
} }
...@@ -2,14 +2,18 @@ ...@@ -2,14 +2,18 @@
namespace App\Models\EmailTemplates; namespace App\Models\EmailTemplates;
use App\Models\EmailTemplates\Traits\Attribute\EmailTemplateAttribute; use App\Models\ModelTrait;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\EmailTemplates\Traits\Attribute\EmailTemplateAttribute;
class EmailTemplate extends Model class EmailTemplate extends Model
{ {
use EmailTemplateAttribute, use ModelTrait,
SoftDeletes; SoftDeletes,
EmailTemplateAttribute {
// EmailTemplateAttribute::getEditButtonAttribute insteadof ModelTrait;
}
/** /**
* The database table used by the model. * The database table used by the model.
......
...@@ -7,36 +7,11 @@ namespace App\Models\EmailTemplates\Traits\Attribute; ...@@ -7,36 +7,11 @@ namespace App\Models\EmailTemplates\Traits\Attribute;
*/ */
trait EmailTemplateAttribute trait EmailTemplateAttribute
{ {
/**
* @return string
*/
public function getEditButtonAttribute()
{
if (access()->allow('edit-email-template')) {
return '<a class="btn btn-flat btn-default" href="'.route('admin.emailtemplates.edit', $this).'" class="btn btn-xs btn-primary"><i class="fa fa-pencil" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.general.crud.edit').'"></i></a> ';
}
}
/**
* @return string
*/
public function getDeleteButtonAttribute()
{
if (access()->allow('delete-email-template')) {
return '<a href="'.route('admin.emailtemplates.destroy', $this).'"
data-method="delete"
data-trans-button-cancel="'.trans('buttons.general.cancel').'"
data-trans-button-confirm="'.trans('buttons.general.crud.delete').'"
data-trans-title="'.trans('strings.backend.general.are_you_sure').'"
class="btn btn-xs btn-danger"><i class="fa fa-times" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.general.crud.delete').'"></i></a>';
}
}
/** /**
* @return string * @return string
*/ */
public function getActionButtonsAttribute() public function getActionButtonsAttribute()
{ {
return '<div class="btn-group action-btn">'.$this->getEditButtonAttribute().'</div>'; return '<div class="btn-group action-btn">'.$this->getEditButtonAttribute('edit-email-template', 'admin.emailtemplates.edit').'</div>';
} }
} }
...@@ -2,13 +2,18 @@ ...@@ -2,13 +2,18 @@
namespace App\Models\Faqs; namespace App\Models\Faqs;
use App\Models\Faqs\Traits\Attribute\FaqAttribute; use App\Models\ModelTrait;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\Faqs\Traits\Attribute\FaqAttribute;
class Faq extends Model class Faq extends Model
{ {
use FaqAttribute, SoftDeletes; use ModelTrait,
SoftDeletes,
FaqAttribute {
// FaqAttribute::getEditButtonAttribute insteadof ModelTrait;
}
/** /**
* The database table used by the model. * The database table used by the model.
......
...@@ -7,34 +7,6 @@ namespace App\Models\Faqs\Traits\Attribute; ...@@ -7,34 +7,6 @@ namespace App\Models\Faqs\Traits\Attribute;
*/ */
trait FaqAttribute trait FaqAttribute
{ {
/**
* @return string
*/
public function getEditButtonAttribute()
{
if (access()->allow('edit-faq')) {
return '<a href="'.route('admin.faqs.edit', $this).'" class="btn btn-flat btn-default">
<i data-toggle="tooltip" data-placement="top" title="Edit" class="fa fa-pencil"></i>
</a>';
}
}
/**
* @return string
*/
public function getDeleteButtonAttribute()
{
if (access()->allow('delete-faq')) {
return '<a href="'.route('admin.faqs.destroy', $this).'"
class="btn btn-flat btn-default" data-method="delete"
data-trans-button-cancel="'.trans('buttons.general.cancel').'"
data-trans-button-confirm="'.trans('buttons.general.crud.delete').'"
data-trans-title="'.trans('strings.backend.general.are_you_sure').'">
<i data-toggle="tooltip" data-placement="top" title="Delete" class="fa fa-trash"></i>
</a>';
}
}
/** /**
* @return string * @return string
*/ */
...@@ -83,8 +55,8 @@ trait FaqAttribute ...@@ -83,8 +55,8 @@ trait FaqAttribute
public function getActionButtonsAttribute() public function getActionButtonsAttribute()
{ {
return '<div class="btn-group action-btn">'. return '<div class="btn-group action-btn">'.
$this->getEditButtonAttribute(). $this->getEditButtonAttribute('edit-faq', 'admin.faqs.edit').
$this->getDeleteButtonAttribute(). $this->getDeleteButtonAttribute('delete-faq', 'admin.faqs.destroy').
$this->getStatusButtonAttribute(). $this->getStatusButtonAttribute().
'</div>'; '</div>';
} }
......
...@@ -2,14 +2,18 @@ ...@@ -2,14 +2,18 @@
namespace App\Models\Menu; namespace App\Models\Menu;
use App\Models\Menu\Traits\Attribute\MenuAttribute; use App\Models\ModelTrait;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\Menu\Traits\Attribute\MenuAttribute;
class Menu extends Model class Menu extends Model
{ {
use MenuAttribute, use ModelTrait,
SoftDeletes; SoftDeletes,
MenuAttribute {
// MenuAttribute::getEditButtonAttribute insteadof ModelTrait;
}
/** /**
* The database table used by the model. * The database table used by the model.
......
...@@ -7,41 +7,14 @@ namespace App\Models\Menu\Traits\Attribute; ...@@ -7,41 +7,14 @@ namespace App\Models\Menu\Traits\Attribute;
*/ */
trait MenuAttribute trait MenuAttribute
{ {
/**
* @return string
*/
public function getEditButtonAttribute()
{
if (access()->allow('edit-menu')) {
return '<a class="btn btn-flat btn-default" href="'.route('admin.menus.edit', $this).'">
<i data-toggle="tooltip" data-placement="top" title="'.trans('buttons.general.crud.edit').'" class="fa fa-pencil"></i>
</a>';
}
}
/**
* @return string
*/
public function getDeleteButtonAttribute()
{
if (access()->allow('delete-menu')) {
return '<a class="btn btn-flat btn-default" href="'.route('admin.menus.destroy', $this).'" data-method="delete"
data-trans-button-cancel="'.trans('buttons.general.cancel').'"
data-trans-button-confirm="'.trans('buttons.general.crud.delete').'"
data-trans-title="'.trans('strings.backend.general.are_you_sure').'">
<i data-toggle="tooltip" data-placement="top" title="Delete" class="fa fa-trash"></i>
</a>';
}
}
/** /**
* @return string * @return string
*/ */
public function getActionButtonsAttribute() public function getActionButtonsAttribute()
{ {
return '<div class="btn-group action-btn"> return '<div class="btn-group action-btn">
'.$this->getEditButtonAttribute().' '.$this->getEditButtonAttribute('edit-menu', 'admin.menus.edit').'
'.$this->getDeleteButtonAttribute().' '.$this->getDeleteButtonAttribute('delete-menu', 'admin.menus.destroy').'
</div>'; </div>';
} }
} }
<?php
namespace App\Models;
trait ModelTrait {
/**
* @return string
*/
public function getEditButtonAttribute($permission, $route)
{
if (access()->allow($permission)) {
return '<a href="'.route($route, $this).'" class="btn btn-flat btn-default">
<i data-toggle="tooltip" data-placement="top" title="Edit" class="fa fa-pencil"></i>
</a>';
}
}
/**
* @return string
*/
public function getDeleteButtonAttribute($permission, $route)
{
if (access()->allow($permission)) {
return '<a href="'.route($route, $this).'"
class="btn btn-flat btn-default" data-method="delete"
data-trans-button-cancel="'.trans('buttons.general.cancel').'"
data-trans-button-confirm="'.trans('buttons.general.crud.delete').'"
data-trans-title="'.trans('strings.backend.general.are_you_sure').'">
<i data-toggle="tooltip" data-placement="top" title="Delete" class="fa fa-trash"></i>
</a>';
}
}
}
\ No newline at end of file
...@@ -53,7 +53,7 @@ class RoleRepository extends BaseRepository ...@@ -53,7 +53,7 @@ class RoleRepository extends BaseRepository
DB::raw("GROUP_CONCAT( DISTINCT permissions.display_name SEPARATOR '<br/>') as permission_name"), DB::raw("GROUP_CONCAT( DISTINCT permissions.display_name SEPARATOR '<br/>') as permission_name"),
DB::raw('(SELECT COUNT(role_user.id) FROM role_user LEFT JOIN users ON role_user.user_id = users.id WHERE role_user.role_id = roles.id AND users.deleted_at IS NULL) AS userCount'), DB::raw('(SELECT COUNT(role_user.id) FROM role_user LEFT JOIN users ON role_user.user_id = users.id WHERE role_user.role_id = roles.id AND users.deleted_at IS NULL) AS userCount'),
]) ])
->groupBy('roles.id'); ->groupBy(config('access.roles_table').'.id', config('access.roles_table').'.name', config('access.roles_table').'.all', config('access.roles_table').'.sort');
} }
/** /**
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment