Skip to content

Commit 0e316be

Browse files
authored
Merge pull request #17 from bvipul/vs_master_trait_change
Added Model Master trait file and done related changes in each module
2 parents 893dae2 + 5ce27ec commit 0e316be

File tree

26 files changed

+234
-344
lines changed

26 files changed

+234
-344
lines changed

app/Console/Commands/Stubs/Attribute.stub

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ trait AttributeClass
1717
*/
1818
public function getActionButtonsAttribute()
1919
{
20-
return '<div class="btn-group action-btn">'.
21-
//call your attribute functions here
22-
'</div>';
20+
return '<div class="btn-group action-btn">
21+
'.$this->getEditButtonAttribute(editPermission, editRoute).'
22+
'.$this->getDeleteButtonAttribute(deletePermission, deleteRoute).'
23+
</div>';
2324
}
2425
}

app/Console/Commands/Stubs/Model.stub

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
namespace DummyNamespace;
44

5+
use App\Models\ModelTrait;
56
use Illuminate\Database\Eloquent\Model;
67
use DummyAttribute;
78
use DummyRelationship;
89

910
class DummyModel extends Model
1011
{
11-
use AttributeName,
12-
RelationshipName;
12+
use ModelTrait,
13+
AttributeName,
14+
RelationshipName {
15+
// AttributeName::getEditButtonAttribute insteadof ModelTrait;
16+
}
1317

1418
/**
1519
* NOTE : If you want to implement Soft Deletes in this model,

app/Console/Commands/Stubs/Repository.stub

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class DummyRepoName extends BaseRepository
4545
public function create(array $input)
4646
{
4747
$dummy_small_model_name = self::MODEL;
48+
$dummy_small_model_name = new $dummy_small_model_name();
4849
if ($dummy_small_model_name->save($input)) {
4950
return true;
5051
}

app/Http/Utilities/Generator.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,22 @@ class Generator
106106
protected $update_permission;
107107
protected $delete_permission;
108108

109+
/**
110+
* Routes
111+
* 1. Edit Route
112+
* 2. Store Route
113+
* 3. Manage Route
114+
* 4. Create Route
115+
* 5. Update Route
116+
* 6. Delete Route.
117+
*/
118+
protected $edit_route;
119+
protected $store_route;
120+
protected $index_route;
121+
protected $create_route;
122+
protected $update_route;
123+
protected $delete_route;
124+
109125
/**
110126
* Repository
111127
* 1. Repository Name
@@ -206,6 +222,14 @@ public function initialize($input)
206222
$this->update_permission = 'update-'.strtolower(str_singular($this->model));
207223
$this->delete_permission = 'delete-'.strtolower(str_singular($this->model));
208224

225+
//Routes
226+
$this->index_route = 'admin.'.strtolower(str_plural($this->model)).'.index';
227+
$this->create_route = 'admin.'.strtolower(str_plural($this->model)).'.create';
228+
$this->store_route = 'admin.'.strtolower(str_plural($this->model)).'.store';
229+
$this->edit_route = 'admin.'.strtolower(str_plural($this->model)).'.edit';
230+
$this->update_route = 'admin.'.strtolower(str_plural($this->model)).'.update';
231+
$this->delete_route = 'admin.'.strtolower(str_plural($this->model)).'.destroy';
232+
209233
//Events
210234
$this->events = array_filter($input['event']);
211235

@@ -342,11 +366,15 @@ public function getFullNamespace($name, $inside_directory = null)
342366
*/
343367
public function createModel()
344368
{
345-
$this->createDirectory($this->getBasePath($this->attribute_namespace));
369+
$this->createDirectory($this->getBasePath($this->removeFileNameFromEndOfNamespace($this->attribute_namespace)));
346370
//Generate Attribute File
347371
$this->generateFile('Attribute', [
348372
'AttributeNamespace' => ucfirst($this->removeFileNameFromEndOfNamespace($this->attribute_namespace)),
349373
'AttributeClass' => $this->attribute,
374+
'editPermission' => $this->edit_permission,
375+
'editRoute' => $this->edit_route,
376+
'deletePermission' => $this->delete_permission,
377+
'deleteRoute' => $this->delete_route
350378
], lcfirst($this->attribute_namespace));
351379

352380
//Generate Relationship File

app/Models/Access/Permission/Permission.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22

33
namespace App\Models\Access\Permission;
44

5-
use App\Models\Access\Permission\Traits\Attribute\PermissionAttribute;
6-
use App\Models\Access\Permission\Traits\Relationship\PermissionRelationship;
5+
use App\Models\ModelTrait;
76
use Illuminate\Database\Eloquent\Model;
87
use Illuminate\Database\Eloquent\SoftDeletes;
8+
use App\Models\Access\Permission\Traits\Attribute\PermissionAttribute;
9+
use App\Models\Access\Permission\Traits\Relationship\PermissionRelationship;
910

1011
/**
1112
* Class Permission.
1213
*/
1314
class Permission extends Model
1415
{
15-
use PermissionRelationship, PermissionAttribute, SoftDeletes;
16+
use ModelTrait,
17+
SoftDeletes,
18+
PermissionAttribute,
19+
PermissionRelationship {
20+
// PermissionAttribute::getEditButtonAttribute insteadof ModelTrait;
21+
}
1622

1723
/**
1824
* The database table used by the model.

app/Models/Access/Permission/Traits/Attribute/PermissionAttribute.php

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,14 @@
77
*/
88
trait PermissionAttribute
99
{
10-
/**
11-
* @return string
12-
*/
13-
public function getEditButtonAttribute()
14-
{
15-
if (access()->allow('edit-permission')) {
16-
return '<a class="btn btn-flat btn-default" href="'.route('admin.access.permission.edit', $this).'">
17-
<i data-toggle="tooltip" data-placement="top" title="Edit" class="fa fa-pencil"></i>
18-
</a>';
19-
}
20-
}
21-
22-
/**
23-
* @return string
24-
*/
25-
public function getDeleteButtonAttribute()
26-
{
27-
if (access()->allow('delete-permission')) {
28-
return '<a class="btn btn-flat btn-default" href="'.route('admin.access.permission.destroy', $this).'" data-method="delete"
29-
data-trans-button-cancel="'.trans('buttons.general.cancel').'"
30-
data-trans-button-confirm="'.trans('buttons.general.crud.delete').'"
31-
data-trans-title="'.trans('strings.backend.general.are_you_sure').'">
32-
<i data-toggle="tooltip" data-placement="top" title="Delete" class="fa fa-trash"></i>
33-
</a>';
34-
}
35-
}
36-
3710
/**
3811
* @return string
3912
*/
4013
public function getActionButtonsAttribute()
4114
{
4215
return '<div class="btn-group action-btn">
43-
'.$this->getEditButtonAttribute().'
44-
'.$this->getDeleteButtonAttribute().'
45-
16+
'.$this->getEditButtonAttribute('edit-permission', 'admin.access.permission.edit').'
17+
'.$this->getDeleteButtonAttribute('delete-permission', 'admin.access.permission.destroy').'
4618
</div>';
4719
}
4820
}

app/Models/Access/Role/Role.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,28 @@
22

33
namespace App\Models\Access\Role;
44

5-
use App\Models\Access\Role\Traits\Attribute\RoleAttribute;
6-
use App\Models\Access\Role\Traits\Relationship\RoleRelationship;
7-
use App\Models\Access\Role\Traits\RoleAccess;
8-
use App\Models\Access\Role\Traits\Scope\RoleScope;
5+
use App\Models\ModelTrait;
96
use Illuminate\Database\Eloquent\Model;
107
use Illuminate\Database\Eloquent\SoftDeletes;
8+
use App\Models\Access\Role\Traits\RoleAccess;
9+
use App\Models\Access\Role\Traits\Scope\RoleScope;
10+
use App\Models\Access\Role\Traits\Attribute\RoleAttribute;
11+
use App\Models\Access\Role\Traits\Relationship\RoleRelationship;
1112

1213
/**
1314
* Class Role.
1415
*/
1516
class Role extends Model
1617
{
1718
use RoleScope,
19+
ModelTrait,
1820
RoleAccess,
1921
RoleAttribute,
2022
RoleRelationship,
21-
SoftDeletes;
23+
SoftDeletes {
24+
RoleAttribute::getEditButtonAttribute insteadof ModelTrait;
25+
RoleAttribute::getDeleteButtonAttribute insteadof ModelTrait;
26+
}
2227

2328
/**
2429
* The database table used by the model.

app/Models/Access/Role/Traits/Attribute/RoleAttribute.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function getDeleteButtonAttribute()
4343
public function getActionButtonsAttribute()
4444
{
4545
return '<div class="btn-group action-btn">
46-
'.$this->getEditButtonAttribute().'
46+
'.$this->getEditButtonAttribute('edit-role', 'admin.access.role.edit').'
4747
'.$this->getDeleteButtonAttribute().'
4848
</div>';
4949
}

app/Models/Access/User/User.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
namespace App\Models\Access\User;
44

5-
use App\Models\Access\User\Traits\Attribute\UserAttribute;
6-
use App\Models\Access\User\Traits\Relationship\UserRelationship;
7-
use App\Models\Access\User\Traits\Scope\UserScope;
8-
use App\Models\Access\User\Traits\UserAccess;
9-
use App\Models\Access\User\Traits\UserSendPasswordReset;
5+
use Illuminate\Notifications\Notifiable;
106
use Illuminate\Database\Eloquent\SoftDeletes;
7+
use App\Models\Access\User\Traits\UserAccess;
8+
use App\Models\Access\User\Traits\Scope\UserScope;
119
use Illuminate\Foundation\Auth\User as Authenticatable;
12-
use Illuminate\Notifications\Notifiable;
10+
use App\Models\Access\User\Traits\UserSendPasswordReset;
11+
use App\Models\Access\User\Traits\Attribute\UserAttribute;
12+
use App\Models\Access\User\Traits\Relationship\UserRelationship;
1313

1414
/**
1515
* Class User.

app/Models/BlogCategories/BlogCategory.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22

33
namespace App\Models\BlogCategories;
44

5-
use App\Models\BlogCategories\Traits\Attribute\BlogCategoryAttribute;
6-
use App\Models\BlogCategories\Traits\Relationship\BlogCategoryRelationship;
5+
use App\Models\ModelTrait;
76
use Illuminate\Database\Eloquent\Model;
87
use Illuminate\Database\Eloquent\SoftDeletes;
8+
use App\Models\BlogCategories\Traits\Attribute\BlogCategoryAttribute;
9+
use App\Models\BlogCategories\Traits\Relationship\BlogCategoryRelationship;
910

1011
class BlogCategory extends Model
1112
{
12-
use BlogCategoryAttribute,
13+
use ModelTrait,
1314
SoftDeletes,
14-
BlogCategoryRelationship;
15+
BlogCategoryAttribute,
16+
BlogCategoryRelationship {
17+
// BlogCategoryAttribute::getEditButtonAttribute insteadof ModelTrait;
18+
}
1519

1620
/**
1721
* The database table used by the model.

0 commit comments

Comments
 (0)