10
10
use Illuminate \Contracts \Container \BindingResolutionException ;
11
11
use Illuminate \Database \Console \DatabaseInspectionCommand ;
12
12
use Illuminate \Database \Eloquent \Relations \Relation ;
13
+ use Illuminate \Support \Facades \Gate ;
13
14
use Illuminate \Support \Str ;
14
15
use ReflectionClass ;
15
16
use ReflectionMethod ;
@@ -103,12 +104,27 @@ public function handle()
103
104
$ class ,
104
105
$ model ->getConnection ()->getName (),
105
106
$ model ->getConnection ()->getTablePrefix ().$ model ->getTable (),
107
+ $ this ->getPolicy ($ model ),
106
108
$ this ->getAttributes ($ model ),
107
109
$ this ->getRelations ($ model ),
108
110
$ this ->getObservers ($ model ),
109
111
);
110
112
}
111
113
114
+ /**
115
+ * Get the first policy associated with this model.
116
+ *
117
+ * @param \Illuminate\Database\Eloquent\Model $model
118
+ * @return Illuminate\Support\Collection
119
+ */
120
+ protected function getPolicy ($ model )
121
+ {
122
+ return collect (Gate::policies ())
123
+ ->filter (fn ($ policy , $ modelClass ) => $ modelClass === get_class ($ model ))
124
+ ->values ()
125
+ ->first ();
126
+ }
127
+
112
128
/**
113
129
* Get the column attributes for the given model.
114
130
*
@@ -266,16 +282,17 @@ protected function getObservers($model)
266
282
* @param string $class
267
283
* @param string $database
268
284
* @param string $table
285
+ * @param string $policy
269
286
* @param \Illuminate\Support\Collection $attributes
270
287
* @param \Illuminate\Support\Collection $relations
271
288
* @param \Illuminate\Support\Collection $observers
272
289
* @return void
273
290
*/
274
- protected function display ($ class , $ database , $ table , $ attributes , $ relations , $ observers )
291
+ protected function display ($ class , $ database , $ table , $ policy , $ attributes , $ relations , $ observers )
275
292
{
276
293
$ this ->option ('json ' )
277
- ? $ this ->displayJson ($ class , $ database , $ table , $ attributes , $ relations , $ observers )
278
- : $ this ->displayCli ($ class , $ database , $ table , $ attributes , $ relations , $ observers );
294
+ ? $ this ->displayJson ($ class , $ database , $ table , $ policy , $ attributes , $ relations , $ observers )
295
+ : $ this ->displayCli ($ class , $ database , $ table , $ policy , $ attributes , $ relations , $ observers );
279
296
}
280
297
281
298
/**
@@ -284,18 +301,20 @@ protected function display($class, $database, $table, $attributes, $relations, $
284
301
* @param string $class
285
302
* @param string $database
286
303
* @param string $table
304
+ * @param string $policy
287
305
* @param \Illuminate\Support\Collection $attributes
288
306
* @param \Illuminate\Support\Collection $relations
289
307
* @param \Illuminate\Support\Collection $observers
290
308
* @return void
291
309
*/
292
- protected function displayJson ($ class , $ database , $ table , $ attributes , $ relations , $ observers )
310
+ protected function displayJson ($ class , $ database , $ table , $ policy , $ attributes , $ relations , $ observers )
293
311
{
294
312
$ this ->output ->writeln (
295
313
collect ([
296
314
'class ' => $ class ,
297
315
'database ' => $ database ,
298
316
'table ' => $ table ,
317
+ 'policy ' => $ policy ,
299
318
'attributes ' => $ attributes ,
300
319
'relations ' => $ relations ,
301
320
'observers ' => $ observers ,
@@ -309,19 +328,24 @@ protected function displayJson($class, $database, $table, $attributes, $relation
309
328
* @param string $class
310
329
* @param string $database
311
330
* @param string $table
331
+ * @param string $policy
312
332
* @param \Illuminate\Support\Collection $attributes
313
333
* @param \Illuminate\Support\Collection $relations
314
334
* @param \Illuminate\Support\Collection $observers
315
335
* @return void
316
336
*/
317
- protected function displayCli ($ class , $ database , $ table , $ attributes , $ relations , $ observers )
337
+ protected function displayCli ($ class , $ database , $ table , $ policy , $ attributes , $ relations , $ observers )
318
338
{
319
339
$ this ->newLine ();
320
340
321
341
$ this ->components ->twoColumnDetail ('<fg=green;options=bold> ' .$ class .'</> ' );
322
342
$ this ->components ->twoColumnDetail ('Database ' , $ database );
323
343
$ this ->components ->twoColumnDetail ('Table ' , $ table );
324
344
345
+ if ($ policy ) {
346
+ $ this ->components ->twoColumnDetail ('Policy ' , $ policy );
347
+ }
348
+
325
349
$ this ->newLine ();
326
350
327
351
$ this ->components ->twoColumnDetail (
@@ -372,7 +396,9 @@ protected function displayCli($class, $database, $table, $attributes, $relations
372
396
if ($ observers ->count ()) {
373
397
foreach ($ observers as $ observer ) {
374
398
$ this ->components ->twoColumnDetail (
375
- sprintf ('%s ' , $ observer ['event ' ]), implode (', ' , $ observer ['observer ' ]));
399
+ sprintf ('%s ' , $ observer ['event ' ]),
400
+ implode (', ' , $ observer ['observer ' ])
401
+ );
376
402
}
377
403
}
378
404
0 commit comments