<?php
require __DIR__ . '/../vendor/autoload.php';
$app=require __DIR__ . '/../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();

$perm = Spatie\Permission\Models\Permission::where('name','view categories')->first();
if(! $perm){ echo "permission not found\n"; return; }

echo 'perm_id=' . $perm->id . PHP_EOL;
$roleIds = Illuminate\Support\Facades\DB::table('role_has_permissions')->where('permission_id',$perm->id)->pluck('role_id')->all();
echo 'role_ids=' . implode(',', $roleIds) . PHP_EOL;
$roleNames = Spatie\Permission\Models\Role::whereIn('id',$roleIds)->pluck('name')->all();
echo 'role_names=' . implode(', ', $roleNames) . PHP_EOL;
