Hey, wow :) I am also studying best practices at the moment and this example of yours is very easy to understand! Thanks! Keep it KISS like it is at the moment :).
What I wanted to add more is testing and custom validation. If you find anything useful send me a pull request.
Yeah, those would be handy as well :). Maybe add some sort of "levels" (branches) where with every level you increase the number of patters/technics used.
edit: Do I need to create a different validation service when I need to have (slightly) different validation rules when updating a model for example?
Maybe some points you could add or at least some inspiration:
Entities http://culttt.com/2014/01/27/creating-entities-laravel-4/
Model Presenters (there are two good packages) http://culttt.com/2014/03/03/model-presenters-laravel-4/
and Caching as a Service: http://culttt.com/2014/02/03/laravel-4-cache-service/
Added custom validation rules through a service provider. Took me 3 days to figure out why it was not working !!
Also, I have restructured the respositories into separate folders.
Ilyes512 said:
Yeah, those would be handy as well :). Maybe add some sort of "levels" (branches) where with every level you increase the number of patters/technics used.
Will see :)
edit: Do I need to create a different validation service when I need to have (slightly) different validation rules when updating a model for example?
You need to add a validator at app/lib/Sampleapp/Services/Validators/YourShinyNewValidator.php, and in your gateway app/lib/Sampleapp/Gateways/SomeGateway.php use
$myValidator = new \Sampleapp\Services\Validators\YourShinyNewValidator($input);
Thats the way it is structured for now.
I think there was a bug in the original code ($input) was not passed to the YourShinyNewValidator. Please check the updated code.
psychonetic said:
Maybe some points you could add or at least some inspiration:
Entities http://culttt.com/2014/01/27/creating-entities-laravel-4/
Model Presenters (there are two good packages) http://culttt.com/2014/03/03/model-presenters-laravel-4/
and Caching as a Service: http://culttt.com/2014/02/03/laravel-4-cache-service/
Will check that next :) Thanks.
I have added reference links in the top of every file, if you need to know the theory behind it then check that link.
Added https://github.com/robclancy/presenter presenter to the 'robclancy-presenter' branch.
https://github.com/octabrain/Laravel4-Patterns/tree/robclancy-presenter
I was not able to get the "Extending the Decorator" working :(
I will try https://github.com/ShawnMcCool/laravel-auto-presenter next.
Just an update.
Integrated presenter https://github.com/ShawnMcCool/laravel-auto-presenter and also updated the readme
https://github.com/octabrain/Laravel4-Patterns/
:)
Edit : Full version is now available at
https://github.com/octabrain/Laravel4-Patterns-Full
I hope this helps :)
I see you also now inject the validator. Although I think it needs to be injected, I don't think that injecting it in the __construct is any helpful, cause you probably want other validator rules for updating a record.
Method injection is going to be so awesome for this (see this Laracast video, it's a Laravel 5 feature).
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community