Align code better using Eloquent's `query` method
I often use Eloquent's `query` just to have the code better aligned#visualdebtisreal pic.twitter.com/0JWrzx6wEN
— Freek Van der Herten (@freekmurze) 2 juli 2018
Read more [twitter.com]
I often use Eloquent's `query` just to have the code better aligned#visualdebtisreal pic.twitter.com/0JWrzx6wEN
— Freek Van der Herten (@freekmurze) 2 juli 2018
Read more [twitter.com]
? Customizing the error bag on a Laravel form request is as easy as setting a property. I find this comes in handy if a template might have multiple error checks. pic.twitter.com/b0lsP5oJ6G
— Paul Redmond ?? (@paulredmond) 26 juni 2018
Read more [twitter.com]
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.
"Freek’s newsletter is one of the best ways to stay updated with the Laravel and PHP ecosystem. It consistently highlights useful packages, tools, and ideas from the community, especially the amazing work coming from Spatie. As a Laravel developer building SaaS and web platforms, I find it extremely helpful to discover practical tools and insights that improve my development workflow."
At Spatie We are currenlty building a new company website. One of the cool features is that it won't set a single cookie. In a new blogpost Dieter Stinglhamber explains how you can achieve this in Laravel.
Since May 25th you have been harassed by "We have updated our privacy policy" emails but also websites started to great you with "Please, let us and our 256 partners track you". In response to these abusive practices, some developers have decided to follow a better path, removing every cookie that is not needed.
Read more [dieterstinglhamber.me]
?? Use Eloquent's "->is()" method for more expressive and thorough assertions pic.twitter.com/8zx8AEm9Rw
— Caleb Porzio (@calebporzio) 22 juni 2018
Read more [twitter.com]
Recently I was working on a client project where a data import was performed via queues. Each record was imported in its own queued job using multiple queue workers. After the data import was done we had more rows than expected in the database. In this blogpost I'd like to explain why that happened.…
Recently Taylor Otwell held a blogging competition. Entries could be submitted on a GitHub repo, the post with the highest amount of ? would win. My colleague Alex wrote a blogpost on how you could easily win the competition by hacking a bit. It's pretty awesome that Alex, without using any of the hacks described in the post, wound up winning the competition.
I feel like programmers are often as good at breaking things as they are at fixing things. Part of the thought process of programming anything new is figuring out its flaws, weaknesses and possible exploitations. As a web developer, I often find myself applying the same thought process to everything I see and read about online. Including Laravel's May Mayhem blog contest.
Read more [alexvanderbist.com]
A few weeks ago Matthieu Napoli released Bref, a tool to get any PHP project up and running in a serverless environment. Matthieu has managed to get working serverless too.
Serverless basically means “Running apps without worrying about servers”. The main difference with a traditional hosting is that you do not maintain the servers and reserve their capacity. They are scaled up or down automatically and you pay only for what you use. ... Today let’s try to deploy a Laravel application on AWS lambda using Bref.
Read more [mnapoli.fr]
Bad title because we don't do overtime at Spatie, but our team has been very busy putting out new open source stuff. In the past weeks our team has released three new packages. In this post I'd like to quickly introduce them too you. sheets First up is spatie/sheets, created by Sebastian. This…
Rémi Collin shares a cool approach on where to place code that doesn't really belong in a controller. He creates small, reusable, testable, decoratable classes, called Actions.
Using this approach can seems a lot of classes at first. And, of course the user registration is a simple example aimed to keep the reading short and clear. Real value starts to become clear once the complexity starts growing, because you know your code is in one place, and the boundaries are clearly defined.
Read more [medium.com]
Christopher Rumpel created a cool BotMan powered quiz on Laravel take you can take via Telegram. In a new blogpost he shares how it was built.
Hey everyone. In this article, I want to show you how I built the LaravelQuiz Chatbot. If you haven't tried it yet, it is a good idea to check it out before reading this article. This will help to understand what I am talking about. Right now it only supports Telegram. The chatbot provides a quiz with all kinds of questions about the Laravel framework. Every question comes with up to three possible answers. You need to pick the right one to collect points and make it to the highscore. But besides the ranks, the quiz is about having a good time. Enjoy the questions and see what you know about Laravel. Have fun!
https://christoph-rumpel.com/2018/05/how-i-built-the-laravelquiz-chatbot-with-botman-and-laravel
I took the quiz and scored pretty good.
? Day2 of LaravelQuiz: We still got 3 players in the top10 who reached the score with their first try ? Nice @freekmurze @adamwathan @ClaudioDekker Can you beat them? https://t.co/AGkBphJWtj pic.twitter.com/bQpKfTg2Z1
— Christoph Rumpel (@christophrumpel) May 25, 2018
? Killing conditionals with Eloquent's "firstOr" method. If firstOrCreate, firstOrFail, or firstOrNew don't quite cut it. pic.twitter.com/PKrtqDc0vl
— Caleb Porzio (@calebporzio) 22 mei 2018
Read more [twitter.com]
? Laravel Quick Tip: Did you know that you can change the keys of a collection to a given value of the collection? ? Perfect for removing items of a collection by the model id. #laravel pic.twitter.com/kgsVnkFCBe
— Christoph Rumpel (@christophrumpel) 24 mei 2018
Read more [twitter.com]
Marcel Pociot, the mind behind BotMan, has released a cool package to create visual diff in your PHPUnit tests. Under the hood it uses our Browsershot package.
I'm not sure how you feel, but I consider myself a backend developer. Sure - I know my way around Vue.JS and really enjoy working with it, but writing CSS has never been my strong point. At one of our companies recent projects, we are working together with another development team, which is mostly taking care of frontend development. So we build controllers, repositories, services, etc. and hand it over to some basic views. They handle the rest. We introduced continuous integration to them and showed them our usual workflow, when I thought that it would be excellent to also have some kind of visual CI for frontend changes.
Read more [marcelpociot.de]
In most applications you store the state of the application in the database. If something needs to be changed you simply update values in a table. When using event sourcing you'll take a different approach. All changes to application state are stored as a series of events. The key benefit here is…
? Did you know you could use the afterCreating and lots of other "after" callbacks on Eloquent Factories to create additional models in Laravel? https://t.co/XejFph55zO #Laravel #PHP pic.twitter.com/oc8BfpEPqN
— Dries Vints (@driesvints) May 15, 2018
Read more [twitter.com]
In a new video Jason McCreary, the creator of the wonderful Laravel Shift, demonstrates a few good tips to clean up code. In the video below Jason uses a code snippet taken from my side project Oh Dear!
If you're interested in more tips from Jason be sure to check out his upcoming BaseCode field guide.
Meanwhile I've cleaned up (and deployed) the code in the actual app. This is what I ended up with:
class Check
{
public function needsToRun(): bool
{
if (!$this->belongsToTeamOnActiveSubscriptionOrOnGenericTrial()) {
return false;
}
if ($this->disabled()) {
return false;
}
if ($this->alreadyRunningOrScheduled()) {
return false;
}
if ($this->didNotRunBefore()) {
return true;
}
if ($this->checkType()->is(CheckType::UPTIME) && $this->latestRun()->failed()) {
return true;
}
if ($this->previousRunCrashed()) {
return true;
}
return $this->latestRun()->endedMoreThanMinutesAgo($this->checkType()->minutesBetweenRuns());
}
protected function checkType(): CheckType
{
return new CheckType($this->type);
}
}
use MyCLabs\Enum\Enum;
class CheckType extends Enum
{
const UPTIME = 'uptime';
const BROKEN_LINKS = 'broken_links';
const MIXED_CONTENT = 'mixed_content';
const CERTIFICATE_HEALTH = 'certificate_health';
const CERTIFICATE_TRANSPARENCY = 'certificate_transparency';
public function minutesBetweenRuns(): int
{
if ($this->getValue() === static::MIXED_CONTENT) {
return 60 * 12;
}
if ($this->getValue() === static::BROKEN_LINKS) {
return 60 * 12;
}
if ($this->getValue() === static::CERTIFICATE_HEALTH) {
return 5;
}
if ($this->getValue() === static::UPTIME) {
return 3;
}
throw new Exception("Minutes between runs not specified for type `{$this->getValue()}`");
}
public function is(string $type): bool
{
return $type === $this->getValue();
}
}
John Bonaccorsi, a developer from Tighten, wrote some good ways of structuring model factories in a Laravel app.
Thanks to class-based model factories, our test setup went from being a bloated mess to simple and succinct. The optional fluent methods give us flexibility and make it obvious when we are intentionally changing our world. Should you read this blog post and immediately go and update all of your model factories to be class-based instead? Of course not! But if you begin to notice your tests feeling top heavy, class-based model factories may be the tool to reach for.
https://tighten.co/blog/tidy-up-your-tests-with-class-based-model-factories
My favorite Laravel feature: `higher order tap`. So simple, yet so powerful. ? pic.twitter.com/cfBU4i0zk7
— Raul (@rcubitto) May 2, 2018
Read more [twitter.com]
Barry van Veen recently fixed an interesting performance issue at our permissions package.
Recently I was investigating the performance of an application we have built at SWIS. To my surprise, one of the most excellent costly methods was part of the spatie/laravel-permission package. After reading some more it was clearly a performance issue that could be improved upon. Since the solution was already clearly outlined it was quite easy to code it and submit a pull request.
https://barryvanveen.nl/blog/46-improving-the-performance-of-spatie-laravel-permission
At Spatie we have over 180 public repositories. Some of our packages have become quite popular. We're very grateful that many of our users open up issues and PRs to ask questions, notify us of problems and try to solve those problems, ... Most of these issues and PRs are handled by our team. But…