Skip to content

Conversation

@mjauvin
Copy link
Member

@mjauvin mjauvin commented Jan 10, 2025

No description provided.

@mjauvin mjauvin added this to the 1.2.8 milestone Jan 10, 2025
@mjauvin mjauvin requested a review from LukeTowers January 10, 2025 16:27
@mjauvin mjauvin self-assigned this Jan 10, 2025
@mjauvin
Copy link
Member Author

mjauvin commented Jan 10, 2025

@sephyld how did you manage to use this before this PR?

@mjauvin
Copy link
Member Author

mjauvin commented Jan 10, 2025

@LukeTowers should I move the HasFactory trait under Database/Traits or Database\Factories\Traits or other ?

@sephyld
Copy link

sephyld commented Jan 12, 2025

@sephyld how did you manage to use this before this PR?

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 $model property.

<?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

@mjauvin
Copy link
Member Author

mjauvin commented Jan 12, 2025

@sephyld how did you manage to use this before this PR?

If you are referring to the factory not managing to resolve the model's class name, I just specify the model class using the $model property.

Actually, I'm referring to the Model not resolving the Factory. i.e. Model::factory() doesn't work without this PR.

@sephyld
Copy link

sephyld commented Jan 13, 2025

@sephyld how did you manage to use this before this PR?

If you are referring to the factory not managing to resolve the model's class name, I just specify the model class using the $model property.

Actually, I'm referring to the Model not resolving the Factory. i.e. Model::factory() doesn't work without this PR.

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

@LukeTowers
Copy link
Member

@sephyld if you're able to improve the magic in Winter at all that would be much appreciated ❤️

@LukeTowers LukeTowers changed the title Fix Database Factory for Winter use Improve support for Factories Feb 1, 2025
@LukeTowers LukeTowers merged commit b9b5aae into develop Feb 1, 2025
10 checks passed
@LukeTowers LukeTowers deleted the factories branch February 1, 2025 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants