Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

eggplantSword's avatar

Seeder not finishing without errors

I have a big seeder that is over 400 lines of code with sets my apps user roles and permissions using laravel-permission by spatie, however when I run it on my server in production, I don't get any errors but the seeder doesn't finish all the way through either.

<?php

namespace Database\Seeders\Tenant;

use App\Enums\Permissions;
use App\Enums\PermissionSuffix;
use App\Models\Auth\Permission;
use App\Models\Auth\Role;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;
use Spatie\Permission\PermissionRegistrar;

class RolesAndPermissionsSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        app(PermissionRegistrar::class)->forgetCachedPermissions();

        Role::updateOrCreate(['name' => 'Super Administrador', 'guard_name' => 'web']);

        $permissions = collect();

//there are around 36 of these `push` because they get separated by permissions like `surveys`, `events`, etc.
        $permissions->push(
          //read, create, update, trash, restore and export permission
        );

        Permission::query()->upsert($permissions->toArray(), ['name', 'guard_name']);

        Role::findOrCreate('Coordinador', 'web')->syncPermissions(
           //perms
        );

        Role::findOrCreate('Back Office', 'web')->syncPermissions(
            //perms
        );

//stops around here
        Role::findOrCreate('Supervisor', 'web')->syncPermissions(
           //perms
        );

        Role::findOrCreate('Mercaderista', 'web')->syncPermissions(
            //perms
        );

        Role::findOrCreate('Cliente', 'web')->syncPermissions(
           //perms
        );
    }
}

I took out most of the code but left the rest to show how it works, the seeder stops after creating the Supervisor role but before it sets the permissions for that role, it leaves roles Mercadersita and Cliente completely out.

What could be causing a seeder to stop on production without any errors?

0 likes
1 reply
LaryAI's avatar
Level 58

There could be a few reasons why the seeder is not finishing without errors on production. Here are a few things to check:

  1. Check the server logs: The server logs may contain errors that are not being displayed on the screen. Check the logs to see if there are any errors that could be causing the seeder to stop.

  2. Increase the memory limit: The seeder may be running out of memory on production. Try increasing the memory limit in the php.ini file or in the .htaccess file.

  3. Check the database: The seeder may be failing because of a database issue. Check the database to see if there are any errors or issues that could be causing the seeder to fail.

  4. Split the seeder into smaller parts: The seeder may be too large to run on production. Try splitting the seeder into smaller parts and running them separately.

  5. Use try-catch blocks: Wrap the code in try-catch blocks to catch any errors that may be occurring and log them to the server.

Here's an example of how to use try-catch blocks in the seeder:

public function run()
{
    try {
        app(PermissionRegistrar::class)->forgetCachedPermissions();

        // rest of the code
    } catch (\Exception $e) {
        // log the error
        \Log::error($e->getMessage());
    }
}

Please or to participate in this conversation.