Home /

Blog

Blog

My random ramblings

Below you can read various blog posts about Laravel, Vue.js or other techniques. That depends on my mood.

Loading blogposts...

Throw custom ValidationException outside Requests

In some cases, you might want to throw a custom ValidationException. This might be required for complicated logic that does not fit in a separate Request class.

Increase Laravel performance with preloading (PHP 7.4+)

The release of PHP 7.4 contained some features focused on performance. One of these features is called preloading. Preloading makes use of a preload script, that will execute on server start-up. This preload script loads cached PHP files into memory. In this blog post, I would like to share an example I discovered in the Front Line PHP book, created by Brent Roose of Spatie. 

Decrease memory usage with the toBase() function

Laravel offers a lot of convenient functions. Using an ORM like Eloquent, a function like BlogPost::all(), not only fetches all blog posts from the database, but also prepares them as Models. This is very convenient if you need to have access to model functions. But what if you do not require these model functions, how can we decrease memory usage and improve performance?

Create migration and controller for make:model using flags

One of the most frequently used commands while building a project is the php artisan make:model command. But did you know you can pass additional flags to quickly generate (RESTful) controllers and a migration file?

Easily share local website using ngrok

Have a small update you would like to showcase to your colleagues? It is incredibly easy to share a local website using ngrok

Read more

3 years ago

Scopes to custom QueryBuilders

As you might be aware, reusing certain query scopes is fairly straightforward using Local scopes. But it feels a bit dirty to bother our models with this logic, especially since every function has to be prefixed with scope. Fortunately, there is an easier way to define these reusable scopes using separate QueryBuilder classes.

Filter index resources Laravel Nova

On the index page of a Laravel Nova Resource, you may notice that all records are loaded. You would think that returning false from the view function in the policy of the related resource would stop specific resources from appearing on the index page. Unfortunately, this is not the case and requires a special approach.

Return primary keys from Eloquent Collections: the simple way

I have been using Laravel for a while now, and every so often I run into a new little trick to make life easier. Today I wanted to share a discovery I made a couple of years ago, that simplified slightly.