Closed JoshKisb closed 1 month ago
45846d6c70
)[!TIP] I can email you next time I complete a pull request if you set up your email here!
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
database/seeders/PermissionsSeeder.php
✗ https://github.com/JoshKisb/genealogy-laravel/commit/093737d789b4070e4ab5da47e3b3e2af57ba145b Edit
Create database/seeders/PermissionsSeeder.php with contents: Create a new file `PermissionsSeeder.php` in the `database/seeders/` directory with the following content:
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\File;
use Spatie\Permission\Models\Permission;
class PermissionsSeeder extends Seeder
{
public function run()
{
$policiesPath = app_path('Policies');
$policyFiles = File::allFiles($policiesPath);
foreach ($policyFiles as $policyFile) {
$policyClass = 'App\\Policies\\' . $policyFile->getFilenameWithoutExtension();
$policyMethods = get_class_methods($policyClass);
foreach ($policyMethods as $method) {
if (in_array($method, ['viewAny', 'view', 'create', 'update', 'delete', 'restore', 'forceDelete'])) {
Permission::findOrCreate($method);
}
}
}
}
}
This seeder class will read all the policy files in the app/Policies/
directory, extract the permission names based on the method names, and create permissions using the Spatie package.
database/seeders/DatabaseSeeder.php
✓ https://github.com/JoshKisb/genealogy-laravel/commit/093737d789b4070e4ab5da47e3b3e2af57ba145b Edit
Modify database/seeders/DatabaseSeeder.php with contents: Add the `PermissionsSeeder` to the `DatabaseSeeder` class to ensure it is executed during database seeding.
I have finished reviewing the code for completeness. I did not find errors for sweep/create_default_permissions_seeder
.
💡 To recreate the pull request edit the issue title or description. Something wrong? Let us know.
This is an automated message generated by Sweep AI.
Details
Create a seeder class database/seeders/PermissionsSeeder.php that creates all the spatie permissions as seen in the policies. app/Policies/*.php
Checklist
- [X] Create `database/seeders/PermissionsSeeder.php` ✗ https://github.com/JoshKisb/genealogy-laravel/commit/093737d789b4070e4ab5da47e3b3e2af57ba145b [Edit](https://github.com/JoshKisb/genealogy-laravel/edit/sweep/create_default_permissions_seeder/database/seeders/PermissionsSeeder.php) - [X] Modify `database/seeders/DatabaseSeeder.php` ✓ https://github.com/JoshKisb/genealogy-laravel/commit/093737d789b4070e4ab5da47e3b3e2af57ba145b [Edit](https://github.com/JoshKisb/genealogy-laravel/edit/sweep/create_default_permissions_seeder/database/seeders/DatabaseSeeder.php)