You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用PHP Faker填充数据报错:Illuminate\Database\Query\Builder::issues不存在

Fixing "Method Illuminate\Database\Query\Builder::issues does not exist" in Lumen Seeder

Hey there, let’s break down what’s causing this error and how to fix it. That message means somewhere in your gamesSeeder code, you’re trying to call an issues() method directly on a query builder instance (like the one you get from DB::table('games')) instead of on a model that has that relationship defined. Here are the most likely fixes:

1. Correct method calls in your gamesSeeder

First, check your seeder code for lines that look like this:

DB::table('games')->issues()->create([...]);

This is the problem—DB::table() returns a query builder, which doesn’t have an issues() method. Instead, use your App\games model and call the relationship on an actual model instance:

// Create a game model instance first
$game = App\games::factory()->create();

// Then call the issues relationship on the instance
$game->issues()->create([...]);

2. Define the issues relationship in your App\games model

If you’re trying to link games to issues via a relationship, you need to add the method to your model. For example, if each game has many issues:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class games extends Model
{
    // ... other model code ...

    public function issues()
    {
        // Adjust the related model and foreign key to match your schema
        return $this->hasMany(App\Issue::class, 'game_id');
    }
}

Make sure the related model (like App\Issue) exists and the foreign key matches your database setup.

3. Check for typos in method names

It’s easy to mistype a method name—double-check if you meant to call something else (like where() or get()) but accidentally wrote issues(). For example, if you had a typo like:

DB::table('games')->issues('status', '=', 'active')->get();

That should be corrected to:

DB::table('games')->where('status', '=', 'active')->get();

4. Verify model imports in your seeder

Make sure you’ve imported the App\games model at the top of your gamesSeeder.php file:

<?php

use App\games;
use Illuminate\Database\Seeder;

class gamesSeeder extends Seeder
{
    // ... seeder code ...
}

This ensures you’re using the model class (which can have relationships) instead of raw database queries.

Once you fix these, running php artisan db:seed should work without that error.

内容的提问来源于stack exchange,提问作者Hanna

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:41:51