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

RoboRobok's avatar

Strange error on seeding: Segmentation fault

I'm seeding my database with sample data. It seeds users, followers, articles and more. I am running the following listener to article saved event:

Article::saved(function ($article) {
    if ($article->getOriginal('published_at') === null && $article->published_at !== null) {
        foreach ($article->user->followers as $follower) {
            $notification = new Notification;
            $notification->type = 'article.published';
            $notification->user()->associate($follower);
            $notification->save();

            $notification->relatedArticles()->save($article);
        }
    }
});

The article seeder is giving me the error:

Segmentation fault

I have no idea why, but after quite long research I found out something very weird. If I change this:

$notification->relatedArticles()->save($article);

To this:

$notification->relatedArticles()->attach($article->id);

It works. What's worth mentioning is that I'm using the same $notification->relatedXXX()->save($XXX); for other models as well and it runs there without a problem.

What can potentially be the reason of this? I might add that for articles I'm running many more queries than for other models, because each user has up to 50 followers in the database. It's still not so many though, I have just a little above 2000 sample records in this notifications relations table.

0 likes
1 reply
uintaam's avatar

Probably too late to answer your question, but do you have an observer that is not using updateQuietly or createQuietly causing an observer loop?

Please or to participate in this conversation.