An interview on Laravel and PHP original
A few days ago I was interviewed by Atif Shahab, PHP community manager at Cloudways, on Laravel and PHP.
A few days ago I was interviewed by Atif Shahab, PHP community manager at Cloudways, on Laravel and PHP.
Today we released a new major version of our laravel-newsletter package. This package makes it easy to integrate MailChimp in your Laravel app. Under the hood V3 of the MailChimp API is used. If you're used the older version of our package be sure to upgrade by the end of this year: MailChimp will…
Join 9,500+ smart developers
Get my monthly newsletter with what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.
No spam. Unsubscribe anytime. You can also follow me on X.
"I’ve been reading freeks newsletter for a while now, and it’s easily one of my favorite developer newsletters. Freek shares practical, no-nonsense insights from running Spatie, maintaining hundreds of open-source packages, and shipping real products. Every time I get useful Laravel tips, smart tooling advice, always high quality and immediately applicable."
It's quite surprising that Laravel didn't have a changelog until today. Community member Till Krüss added one and will probably maintain it in the foreseeable future. The changelog can be viewed on GitHub.
Yesterday, after a winter sleep, PHPGent awoke and held a meetup at the offices of In The Pocket. It was nice to see some familiar and some new faces.
I had the honor of being the first speaker. My talk was titled "Backing up with Laravel". I started off with some best practices regarding backups and demonstrated the laravel-backup package which was released a few weeks ago.
Here are my slides:
https://speakerdeck.com/freekmurze/backing-up-with-laravel
Next up was Wouter Sioen of SumoCoders. He talked about building maintainable software. He showed how using the solid principles help to clean up the code of his home brew json to html converter. Then he continued with explaining object calisthenics: a few simple rules to greatly improve the readability of your code. Wouter's slides can found on github.io.
These two very beautiful graphic summaries of the talks were made by Peter Decuyper:
https://twitter.com/sgrame/status/720674134041235456
https://twitter.com/sgrame/status/720690758265778176
If you attended the meetup be sure to leave Wouter and me some feedback on joind.in so we can improve our speaking skills.
Visiting your local PHP user group is one of the best ways to learn new stuff and to getting to know the community. If you've never visited a user group, use this site to lookup the closest one to your home. If there isn't one close by, start one yourself.
Today we tagged a new major version of laravel-medialibrary. In case you're not familiar with this package here's a quick rundown of what it can do. The package can associate all sorts of files with Eloquent models. It provides a simple, fluent API to work with. Here's a quick example: $newsItem =…
This is a technique that I recently found useful. Eloquent models allow you to specify a custom collection object to be returned – which sometimes can be a great place to put some business logic.https://michaelstivala.com/pushing-logic-custom-collections/
Over at Envato Tuts Alireza Rahmani Khalili wrote a good article on Laravel Facades.
Sweet syntax, which Laravel uses, makes writing code cleaner and easier to understand. Laravel facades are actually the syntactic sugar for service location.http://code.tutsplus.com/tutorials/what-are-laravel-50-facades--cms-25347Let’s take a look at Laravel Facade and the way it functions.
Spatie, the company where I work, is located in Belgium. Although our country is quite small, there are three official languages: Dutch, French and German. That's why nearly all of our projects are multilingual. In most projects we used to rely on Dimitris Savvopoulos popular translatable package to…
For a site I was working on the admin should be able to switch on or off a form that's displayed on the homepage. Question: where's the best place to store the value of that switch? Creating a table and column for it in the database seems overkill. Putting it in a never expiring cache does not feel right. I think the best place to store such value is just write it to a simple file.
In the example above only one value needed to be stored, but for other projects there sometimes were two or three of them. Over the years I found myself writing the same code over and over again to store and work with such values.
Our intern Jolita and I whipped up a valuestore package. It only provides one class: Valuestore. The values will get written as JSON in a given file. The API mostly reflects Laravel's caching API. Here's how you can work with it:
$valuestore = Valuestore::make($pathToFile);
$valuestore->put('key', 'value');
$valuestore->get('key'); // Returns 'value'
$valuestore->has('key'); // Returns true
// Specify a default value for when the specified key does not exist
$valuestore->get('non existing key', 'default') // Returns 'default'
$valuestore->put('anotherKey', 'anotherValue');
// Put multiple items in one go
$valuestore->put(['ringo' => 'drums', 'paul' => 'bass']);
$valuestore->all(); // Returns an array with all items
$valuestore->forget('key'); // Removes the item
$valuestore->flush(); // Empty the entire valuestore
$valuestore->flushStartingWith('somekey'); // remove all items who's keys start with "somekey"
$valuestore->increment('number'); // $valuestore->get('key') will return 1
$valuestore->increment('number'); // $valuestore->get('key') will return 2
$valuestore->increment('number', 3); // $valuestore->get('key') will return 5
// Valuestore implements ArrayAccess
$valuestore['key'] = 'value';
$valuestore['key']; // Returns 'value'
isset($valuestore['key']); // Return true
unset($valuestore['key']); // Equivalent to removing the value
// Valuestore impements Countable
count($valuestore); // Returns 0
$valuestore->put('key', 'value');
count($valuestore); // Returns 1
As you see it's quite a simple class, but I'm sure it'll come in handy in the future. The package can be found on GitHub.
At Spatie we do not only create a lot of Laravel packages, but we use also use a bunch of existing ones. In this post I'd like to give a quick hint to our fellow package developers. In the readme's of packages you'll often find an instruction like this to publish it's assets: php artisan…
Imagine you are working on new app. Your client wants to see the progress that you've made. However your site isn't ready for prime time yet. Sure, you could create some login functionality and display the site only to logged in users. But why bother creating users when there is a more pragmatic approach?
At Spatie we often instruct a client to visit /demo. Visiting that url will unlock access to the entire front site. Because creating packages has many benefits we decided to open source our solution.
Our newly released laravel-demo-mode package blocks your work in progress from prying eyes. After it is installed you can use a route macro to register a route that grants access to the protected routes:
Route::demoAccess('/demo');
Routes can be protected by using the demoMode-middleware on them:
Route::group(['middleware' => 'demoMode'], function () {
Route::get('/secret-route', 'SecretController@index');
});
Unless a user has first visited /demo first, he or she will be redirected to /under-construction. This url can be changed in the config file.
A word to the wise: do not use this package to restrict access to sensitive data or to protect an admin section. For those cases you should use proper authentication.
You can take a look at the package on GitHub. If you like it, you might like some of our other Laravel packages as well.
Virtually every website displays some sort of menu. Generating html menus might seem simple, but it can become complex very quickly. Not only do you have to render some basic html, but you also have to manage which item is active. If a menu has a submenu you'll also want the parents of an active…
Most databases will contain some records that must be cleaned up. The reasons why a record can become unneeded are diverse: maybe it's a temporary record that was only needed for a little while if you're logging stuff to a table, a record may become too old to be of interest anymore ... To help a…
Jeroen Moens posted a, very well written, article on paying technical debt in a legacy codebase.
How can you get a legacy codebase under control and bring it to a new level of maturity? This post summarises my advice and lessons learned from years of working on a large legacy web application.http://marketing.intracto.com/paying-technical-debt-how-to-rescue-legacy-code-through-refactoring
On a sidenote: as an Artisan I always like to sneak in a little Laravel in legacy projects. There are a lot of Illuminate components take can be used independently outside Laravel. If you want to do this too take a look at Matt Stauffer's Torch repo on GitHub.
Mohamed Said created a package that saves all mails sent out by a Laravel application to html files on disk. This can be incredibly useful when designing and debugging mails. It's implemented as a Laravel mail driver. Once installed you'll only have to change your driver to preview.
Take a look at the package on GitHub.
Eric L. Barnes, the curator of Laravel News, recently launched his new website called dotdev. It aims to be a resource for developers who want to read quality reviews and tutorials amongst other things.
Although the site in general doesn't focus on Laravel, Eric wrote a good introductory post for people who are new to the framework. Unlike most beginner level articles, it focuses on creating a real world application.
My goal with this is to create a guide for those just learning the framework. It is setup to take you from the very beginning of an idea into a real deployable application. ... I am attempting to go through the process of creating a new application just as I would in a real world environment. In fact, the code and idea is taken from a project that I built.
https://dotdev.co/tutorials/step-by-step-guide-to-building-your-first-laravel-application/
For the first batch of posts on the site I made a playlist for coding late at night. Do you have something to share that would interest the readers of dotdev? Read these guidelines on guest posting first, and thenemail Eric.
Mohamed Said made a great overview of new features that will be added to Laravel 5.2.23
By the time of writing this post, Laravel has 911 contributors on GitHub, some of them are actively adding awesome stuff to the framework on a daily basis. This is a wrap up for the new stuff in Laravel 5.2.23.http://themsaid.github.io/laravel-5-2-23-20160305/
Today our team released a new major version of laravel-backup. It can backup the files and databases of your application to one or more external filesystems. It uses Laravel's native cloud filesystem to do this. The package can also notify you via Slack and/or email when something goes wrong with…
Yesterday our newest package laravel-feed was released. It makes generating RSS feeds in Laravel very easy. It's very opinionated to fit the needs of our projects, but I believe lots of other developers will find it useful too. There's almost no coding involved to create some feeds. Installation…
Michael Stivala, the Maltese Artisan, wrote a nice introduction to Elasticsearch and how you can use it in Laravel.
https://michaelstivala.com/learning-elasticsearch-with-laravelIn this post we’ll explore Elasticsearch; the basics of search and how to set it up with Laravel, Homestead and even Forge. Even though there are resources out there, I couldn’t find the one article that summarised everything I needed to get up and running in as short a time as possible.