laravel-beyond
laravel-beyond copied to clipboard
add trait command
As https://github.com/regnerisch/laravel-beyond/issues/54 requested, I have created beyond:make:trait
command.
The trait is created in Domain\XXX\Traits
namespace by default.
You can add --support
flag to create the trait in Support\Packages\Laravel\Traits
namespace.
Thank you for your PR. I made a few comments. I'll provide changes if wanted in the evening.
I would expect traits to live only inside the Support
namespace, as you can use them everywhere. See example below:
trait Debug
{
protected function log($exception)
{
// do something special for debug logging
}
}
Thank you for your comments, I have made the changes, hope everything is good!
You are close :)
I also want to say thank you, for your contribution! It's nice to see people helping us with this little project.
This project is gold to me, so It's an honor to contribute on it!
If I understand correctly, it seems you don't want Traits
in the Domain
namespace, and only create them in Support
.
In my case, I need to create a trait in the Domain, like this:
<?php
namespace Domain\Authentication\Traits;
trait HasActivationCode
{
// ...
}
And use it in my User model:
<?php
namespace Domain\Users\Models;
use Domain\Authentication\Traits\HasActivationCode;
class User extends Authenticatable implements MustVerifyEmail
{
use HasActivationCode;
// ...
}
I am not very experimented in DDD, so maybe this is not the proper way to do that 🤷
Yes, I only want them to be created inside the Support
namespace.
Traits are properties and methods you can reuse in every class. It is quite unlikely you will create a trait which is reused in only one specific domain. So I would expect traits to be created inside the Support
namespace to not violate separation by accident (e.g. using a trait of another domain)
We have two options here: Forcing creation inside one specific namespace, or remove the command to not force creation in one namespace. I prefer the former. You are always free to move your trait elsewhere if it fits better.