3 ms·
Have you tried working with Laravel 5.2+ ? Instead of doing tons of for-loops, etc.. You can easily create a collection from data and process it. For example u
by gremlinsinc 10y ago
Have you tried working with Laravel 5.2+ ? Instead of doing tons of for-loops, etc..
You can easily create a collection from data and process it. For example using the DB class to get data returns an array of Std objects.
For a legacy app I'm working w/ --it needs to be an array of arrays... I could for loop, and then add each to a new array.. or I can simply do:
$data = DB::table('something')->where('something')->get();
return collect($data)->map(function($x) { return (array) $x });
There's a talk at lara-con on using collections to replace just about all loops, and it's pretty insightful and makes code so much more readable and enjoyable.
PHP by itself can be ugly -- but the Laravel community has created something beautiful from what used to be akin to horse shit.
- dreistdreist 10y agoLaravel is still horse shit that does not follow good OOP practices. Static calls and active record are not good OOP. Neither are Std objects. Have a look at doctrine if you need an ORM. Otherwise read up on DDD and SOLID.