Using view models

Link – stitcher.io

Brent explains what view models are and how you can use them. We use view models in almost every project at Spatie.

In essence, view models are simple classes that take some data, and transform it into something usable for the view. In this chapter I'll show you the basic principles of the pattern, we'll take a look at how they integrate in Laravel projects, and finally I'll show you how we use the pattern in one of our projects.

Read more [stitcher.io]

Stay up to date with all things Laravel, PHP, and JavaScript.

Follow me on Twitter. I regularly tweet out programming tips, and what I myself have learned in ongoing projects.

Every two weeks I send out a newsletter containing lots of interesting stuff for the modern PHP developer.

Expect quick tips & tricks, interesting tutorials, opinions and packages. Because I work with Laravel every day there is an emphasis on that framework.

Rest assured that I will only use your email address to send you the newsletter and will not use it for any other purposes.

No, disabling a button is not app logic

Link – dev.to

David Khourshid explains how you can use state machines to make your logic more resilient.

Disabling a button is not logic. Rather, it is a sign that logic is fragile and bug-prone. In my opinion, disabling a button should only be a visual cue to the user that clicking the button will have no effect.

Read more [dev.to]

Getting started with GitHub Actions and Laravel

Link – rubenvanassche.com

My colleague Ruben explores the wonderful world of GitHub actions.

You can write workflows in YAML, which makes them easy to write and read. In the beta version of GitHub Actions you had to use Ocaml, which was quite hard to comprehend, and there was almost no documentation. If you were a bit frightened by the beta version, like me, then rest assured: the YAML version is easier to use, and the documentation is well written.

Read more [rubenvanassche.com]

Streamlining Laravel

Link – jasonmccreary.me

JMac, the creator of Laravel Shift, has a few interesting ideas on how to make the framework better.

Every so often a revolutionary change is required. This provides a chance to revisit goals. One of the primary goals of Laravel is developer experience. And maintainability, freshness, and approachability all improve developer experience. So, with all this in mind here are the top five things I would change in Laravel.

Read more [jasonmccreary.me]

Streaming a large export as a CSV file to the browser

Original – by Freek Van der Herten – 3 minute read

A while ago, I created an easy to use framework agnostic PHP package to read and write CSV and Excel files called spatie/simple-excel. Behind the scenes, generators are used to ensure low memory usage, even when working with large files. Today I added a method that allows you to stream CSV files to the browser. In this small blog post, I'd like to demonstrate how you can use it.

Read more

PHP 7.4 FFI: What you need to know

Link – jolicode.com

FFI lets you include external libraries written in other programming languagues in your PHP code.

PHP Foreign Function Interface, or FFI for fans, is a PHP extension that allows you to include with ease some externals libraries into your PHP code. That means it’s possible to use C, Go, Rust, etc. shared library directly in PHP without writing a PHP Extension in C. This concept exists for years in other languages like Python or Go.

Read more [jolicode.com]

Name the Date

Link – medium.com

Kevlin Henney wrote a good post on the importance of naming things well.

Good naming is part of design. It sets expectations and communicates a model, showing how something should be understood and used. If you mean to tell the reader getMillisSince1970, don’t say getTime.

Read more [medium.com]