How to generate dummy anonymous class in Laravel factory

Viewed 341

I want to generate some dummy anonymous class data, However, it seems that the factory::define method only accept Class, I have tried these, but still with no avail

$factory->define(stdClass::class, function($faker) {
    return [
        "hello" => "world"
    ];
});

or even

$factory->define("CUSTOMOBJECT", function($faker) {
    return [
        "hello" => "world"
    ];
});

so that I could generate something like this;

factory("CUSTOMOBJECT")->make() // generate some anonymous object with field hello and value world

Is there a way that I could do the same thing without any class definition but still in the Laravel's 'factory way'? Any solution or any other approach to hide complexities in making a dummy object is appreciated.

0 Answers
Related