Closed mehrancodes closed 4 years ago
Hi @mehrancodes
Thanks for your suggestion. I think what you're asking for is already covered by Poser. You can learn more here: https://github.com/lukeraymonddowning/poser#models-location
If you need to override the model location for a single instance, you can override the $modelName static variable in your Factory class, passing it the fully qualified class name of the corresponding model.
If I'm not on your wavelength, let me know!
I see, but it supports up to 1 namespace for models. It would be nice if we can use it via Models in multiple namespaces...
The base model namespace is always App\
but we can't have Poser Factories for this namespace as well as multiple other namespaces like Package\Foo
If you need to override the model location for a single instance
So before we go ahead with this, just to be super sure, this doesn't solve your query? Sorry for the confusion 👍
<?php
namespace Tests\Factories;
use Lukeraymonddowning\Poser\Factory;
class CommentFactory extends Factory {
public static $modelName = "Package\Foo\Comment";
}
Ahaa!! that's it!! super cool!
btw I have added support for Laravel 5.8 on my clone, as I don't have time to upgrade the project yet, and it works great!
Glad it all worked out! Thanks @mehrancodes, awesome work 👍🥳
Stay safe and happy programming!
It would be awesome if we could have support for multiple namespaces, it is useful when we have internal packages inside our project.
If we want this to happen, we should get the model namespace from the Poser Factories instead of the config file, which this way we can put our models anywhere and just refer to them inside the Poser Factories (As we do already).
I haven't tested this idea yet but I would like to give it a try at the weekend.
Thanks for this awesome tool!!