-
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Database Factory for Winter use #201
base: develop
Are you sure you want to change the base?
Conversation
@sephyld how did you manage to use this before this PR? |
@LukeTowers should I move the |
src/Database/Factories/Factory.php
Outdated
use Illuminate\Support\Str; | ||
|
||
/** | ||
* @template TModel of \Illuminate\Database\Eloquent\Model |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this used for? Should it be pointing at the winter base model class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, I copied this from Laravel.
I tried removing it completely and things still work as expected. It's probably only used by the docblock generator.
/** | ||
* Get a new factory instance for the model. | ||
*/ | ||
public static function factory(callable|array|int|null $count = null, callable|array $state = []): BaseFactory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be returning a Winter BaseFactory, instead of a Laravel one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if we also change this in Winter repo's create:factory
stub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here: modules/system/console/scaffold/factory/factory.stub
Hi @mjauvin. If you are referring to the factory not managing to resolve the model's class name, I just specify the model class using the <?php
namespace Winter\Demo\Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Winter\Demo\Models\ModelKlass;
/**
* ModelKlassFactory Factory
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\Winter\Demo\Models\ModelKlass>
*/
class ModelKlassFactory extends Factory
{
protected $model = ModelKlass::class;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
// factory definition
];
}
} In hindsight, I think I should have added it in the PR that took care of the create:factory command. Sorry. If you want, I can take care of it now |
Actually, I'm referring to the Model not resolving the Factory. i.e. |
I see. I didn't think about that, I never use the model class to resolve its factory. I only use the factory class directly |
@sephyld if you're able to improve the magic in Winter at all that would be much appreciated ❤️ |
No description provided.