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

sandaur's avatar

ERROR: Call to a member function define() on null

Hello, i had this error in Laravel. I was changing a blade template when this occur and now Laravel gives me this error in every page. Any idea?

<?php
 
use Faker\Generator as Faker;
 
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| This directory should contain each of the model factory definitions for
| your application. Factories provide a convenient way to generate new
| model instances for testing / seeding your application's database.
|
*/
 
$factory->define(App\User::class, function (Faker $faker) {   \ <<<---- here it gives me the error
    return [
        'name' => $faker->name,
        'email' => $faker->unique()->safeEmail,
        'password' => 'y$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret
        'remember_token' => str_random(10),
    ];
});

0 likes
6 replies
crnkovic's avatar

What did you change? You have an error somewhere else in your code. Show us the template you changed, or last code you changed.

sandaur's avatar

I undid the changes, i even make a the route "/" return "hello" and nothing. This occurred when i was using FileZilla and my internet went down for a moment and FileZilla lost connection, maybe the ftp client corrupted some file?

Cronix's avatar
Cronix
Best Answer
Level 67

Reupload everything?

I don't see how the problem could be in the code you're posting. Usually that would only be used if you're seeding your database or something. It's not something you'd normally do in a controller.

Most likely this is going to be a huge pain to track down what's happening. I'd just reupload all of your code if you had a problem when uploading it last time. I'm sure it will take less time than tracking down the cause of this.

1 like
sandaur's avatar

it worked, the database folder had vanished somehow. Thanks.

fulopattila122's avatar

I had this problem and in my case the problem was the following:

  • tests in the tests/ folder
  • factories in the tests/factories folder
  • phpunit.xml had: <directory suffix=".php">./tests</directory>

Ie. I made phpunit greedy, because it tried to load (include) upfront the factory files from the tests/factories folder.

I fixed it by modifying phpunit.xml so that it only loads files ending with Test.php:

<phpunit colors="true" bootstrap="./vendor/autoload.php">
    <testsuites>
        <testsuite name="My Test Suite">
            <directory suffix="Test.php">./tests</directory>
        </testsuite>
    </testsuites>
</phpunit>

Please or to participate in this conversation.