This repository has been archived on 2025-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
oliverdavies.uk-old-sculpin/source/_posts/examples-of-laravel-collections-in-drupal.md
Oliver Davies 85a10c545b Run prettier on all *.md files
```
prettier '{app,source}/**/**.md' --write
```
2020-03-08 17:57:45 +00:00

4.5 KiB
Raw Permalink Blame History

title date excerpt tags has_tweets
Examples of using Laravel Collections in Drupal 2018-08-23 Some examples of using Laravels Illuminate Collections within Drupal projects.
drupal
drupal-7
drupal-8
drupal-planet
laravel
laravel-collections
php
true

Since starting to work with Laravel as well as Drupal and Symfony, watching Adam Wathans Refactoring to Collections course as well as lessons on Laracasts, Ive become a fan of Laravels Illuminate Collections and the object-orientated pipeline approach for interacting with PHP arrays.

In fact Ive given a talk on using Collections outside Laravel and have written a Collection class module for Drupal 7.

Ive also tweeted several examples of code that Ive written within Drupal that use Collections, and I thought it would be good to collate them all here for reference.

Thanks again to Tighten for releasing and maintaining the tightenco/collect library that makes it possible to pull in Collections via Composer.

{% include 'tweet' with { class: 'block mb-4 lg:w-1/2 lg:px-2 lg:mb-0', data_cards: true, content: '

Putting @laravelphp's Collection class to good use, cleaning up some of my @drupal 8 code. Thanks @TightenCo for the Collect library! pic.twitter.com/Bn1UfudGvp

— Oliver Davies (@opdavies) August 18, 2017', } %}
{% include 'tweet' with {
    class: 'block mb-4 lg:w-1/2 lg:px-2 lg:mb-0',
    data_cards: true,
    content: '<p lang="en" dir="ltr">Putting more <a href="https://twitter.com/laravelphp?ref_src=twsrc%5Etfw">@laravelphp</a> Collections to work in my <a href="https://twitter.com/drupal?ref_src=twsrc%5Etfw">@drupal</a> code today. 😁 <a href="https://t.co/H8xDTT063X">pic.twitter.com/H8xDTT063X</a></p>&mdash; Oliver Davies (@opdavies) <a href="https://twitter.com/opdavies/status/963890078933282817?ref_src=twsrc%5Etfw">February 14, 2018</a>',
} %}

{% include 'tweet' with {
    class: 'block mb-4 lg:w-1/2 lg:px-2 lg:mb-0',
    data_cards: true,
    content: '<p lang="en" dir="ltr">I knew that you could specify a property like &#39;price&#39; in Twig and it would also look for methods like &#39;getPrice()&#39;, but I didn&#39;t know (or had maybe forgotten) that <a href="https://twitter.com/laravelphp?ref_src=twsrc%5Etfw">@laravelphp</a> Collections does it too.<br><br>This means that these two Collections return the same result.<br><br>Nice! 😎 <a href="https://t.co/2g2IfThzdy">pic.twitter.com/2g2IfThzdy</a></p>&mdash; Oliver Davies (@opdavies) <a href="https://twitter.com/opdavies/status/1009451206765416448?ref_src=twsrc%5Etfw">June 20, 2018</a>',
} %}

{% include 'tweet' with {
    class: 'block mb-4 lg:w-1/2 lg:px-2 lg:mb-0',
    data_cards: true,
    content: '<p lang="en" dir="ltr">More <a href="https://twitter.com/laravelphp?ref_src=twsrc%5Etfw">@laravelphp</a> Collection goodness, within my <a href="https://twitter.com/hashtag/Drupal8?src=hash&amp;ref_src=twsrc%5Etfw">#Drupal8</a> project! <a href="https://t.co/mWgpNbNIrh">pic.twitter.com/mWgpNbNIrh</a></p>&mdash; Oliver Davies (@opdavies) <a href="https://twitter.com/opdavies/status/1027843931101380608?ref_src=twsrc%5Etfw">August 10, 2018</a>',
} %}

{% include 'tweet' with {
    class: 'block mb-4 lg:w-1/2 lg:px-2 lg:mb-0',
    data_cards: true,
    content: '<p lang="en" dir="ltr">Some more <a href="https://twitter.com/hashtag/Drupal?src=hash&amp;ref_src=twsrc%5Etfw">#Drupal</a> 8 fun with Laravel Collections. Loading the tags for a post and generating a formatted string of tweetable hashtags. <a href="https://t.co/GbyiRPzIRo">pic.twitter.com/GbyiRPzIRo</a></p>&mdash; Oliver Davies (@opdavies) <a href="https://twitter.com/opdavies/status/1032544228029673472?ref_src=twsrc%5Etfw">August 23, 2018</a>',
} %}