@@ -223,6 +223,16 @@ public function hasPermissionViaRole(PermissionContract $permission)
223
223
return $ this ->hasRole ($ permission ->roles );
224
224
}
225
225
226
+ /**
227
+ * General action matches with all other actions
228
+ *
229
+ * @return string
230
+ */
231
+ protected function generalAction ()
232
+ {
233
+ return '* ' ;
234
+ }
235
+
226
236
/**
227
237
* Determine if the model has permission to run an action over given entity.
228
238
*
@@ -234,10 +244,13 @@ public function hasPermissionViaRole(PermissionContract $permission)
234
244
public function hasPermissionTo ($ action , $ entity = null ) : bool
235
245
{
236
246
$ entity = array_pop ($ entity );
237
-
238
247
$ permission = $ this
239
248
->getPermissionModel ()
240
- ->where ('action ' , '= ' , $ action )
249
+ ->where (function ($ query ) use ($ action ) {
250
+ $ query
251
+ ->where ('action ' , '= ' , $ action )
252
+ ->orWhere ('action ' , '= ' , $ this ->generalAction ());
253
+ })
241
254
->when (
242
255
!empty ($ entity ),
243
256
function ($ query ) use ($ entity ) {
@@ -246,8 +259,8 @@ function ($query) use ($entity) {
246
259
$ entityName = array_search ($ entityClassName , Relation::$ morphMap );
247
260
248
261
$ query
249
- ->where ('name ' , '= ' , $ entityClassName )
250
- ->orWhere ('name ' , '= ' , $ entityName );
262
+ ->where ('entity_type ' , '= ' , $ entityClassName )
263
+ ->orWhere ('entity_type ' , '= ' , $ entityName );
251
264
});
252
265
253
266
if (is_object ($ entity ) && !empty ($ entity ->id )) {
0 commit comments