Closed sarfraznawaz2005 closed 8 years ago
Well, I've few opinions here:
Don't you agree, Or have different thoughts..?
I agree with you, having $rules array in model is especially inspired by Ruby on Rails apps, their models have validation rules as well as relationships as simple arrays which makes it easy to manage just at "one place". May be that's why Ardent is so popular. Secondly creating Form Requests, etc makes things more complex and time-consuming. Although it is different topic whether to put them in the model itself or not.
If we are to use this package, we have to go back and forth in writing repositories and also update laravel models for validations, relationships, etc, it would have been great if this was one place. I just felt the need of defining validation rules in repositry class which extends EloquentRepository
something like:
protected $repositoryId = 'rinvex.repository.users';
protected $model = User::class;
protected $rules = [];
Having said that, I agree with you may be purpose of package is just focused on Repository Pattern (in which case it should also be framework-agnostic).
Thanks
To be honest, I've thought about including validation features in this package before. I just still don't have a solid opinion on that yet. On a side note, I agree that maintaining form requests adds a more complexity to the project.
May be, let's keep this issue open and see what other users have to say ?
BTW thanks for awesome package :-)
My +1 for this feature :)
Sounds great, and here's my thoughts as well, maybe someone will have vision of the ultimate validation solution 😄
These points IMHO weights each other, maybe someone have a better description & could convince us or reads things differently? Hopefully yes 😃 👍
@ionut-tanasa @rsdev000 @evsign As heavy users of this package, what do you think of this proposal?
Hi. I don't have a opinion about performing validation inside the repo too. I've seen validation within the model, within controller and form requests. For medium (almost large) / large apps I prefer form request. It's centralized too. For small/medium (almost small) apps with less than half-dozen forms I would validate the data within the model. The only con I see is giving this package too many responsabilities.
Cheers
Hmm makes sense, cons seem to over-weigh the pros and you guys have raised valid points and package should not have too many responsibilities at the cost of possible technical debts.
In a "clean" way, respecting SRP and so on, the data needs to be validated before hitting the repository layer. The repository has to be dumb. It just takes the data and shoves it into a database.
Talking from my experience I prefer to use FormRequests. But not always are enough. I still use the good old Validator class. It depends on the use case.
And I think that the rules are useless on the repository if you use another package/or laravel itself to validate. At this point we could add the entire validation process inside the repository.
Agree with @ionut-tanasa, @rsdev000 and @Omranic ) I think form requests and maybe models are the best place to perform data validation.
I'm glad we had this fruitful conversation, and the output we concluded 😄 Thanks everybody 👍 We keep this package focused on what it can do best, repositories & caching layer 😉
It would be awesome if model validation rules array is added to package because then we won't need to use separate package (like Ardent) just for that.
Any thoughts about this ?
Thanks