Sevalla is the all-in-one PaaS for your web projects. Host and deploy your applications, databases, object storage, and static sites. Enjoy advanced deployment pipelines, a complete database studio, instant preview apps, and one-click templates. The pricing is simple: no hidden fees, no seat-based pricing, and you pay only for what you use. Get real human support from developers.

Get started now with a $50 credit at Sevalla.com.

Redirect every request in a Laravel app

Original – by Freek Van der Herten – 1 minute read

I recently had to redirect every single request in a Laravel app. You might think that would be as easy as this: Route::get('/', function() { return redirect('https://targetdomain.com'); }); But that'll only redirect the "/" page. All other requests will return a 404.…

Read more

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

You can follow me on these platforms:

On all these platforms, regularly share programming tips, and what I myself have learned in ongoing projects.

Every month 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.

A middleware to check abilities on the route level

Original – by Freek Van der Herten – 1 minute read

Laravel's native authorization functionality allows you to define abilities a user can have. There are multiple ways to check if a user has a certain ability: via the facade, via the user model, within blade templates and within form requests. What Laravel doesn't provide out of the box is a…

Read more

Functional programming design patterns

Link –

In object-oriented development, we are all familiar with design patterns such as the Strategy pattern and Decorator pattern, and design principles such as SOLID.

The functional programming community has design patterns and principles as well.

This talk will provide an overview of some of these, and present some demonstrations of FP design in practice.

Watch it on Vimeo.

Read more

The Star Wars Holiday Special

Link –

Like most geeks out there I'm a big fan of Star Wars. Many will agree that the original trilogy is far superior to the prequel triology. Until yesterday I thought Episode II was the worst movie of the entire series. But then I found out about the holiday special.

The Star Wars Holiday Special was made in 1978, a year after the original movie. The storyline (quoted from Wikipedia) sounds quite good:

... Chewbacca and Han Solo visit Kashyyyk, Chewbacca's home world, to celebrate Life Day. They are pursued by agents of the Galactic Empire, who are searching for members of the Rebel Alliance on the planet. The special introduces three members of Chewbacca's family: his father Itchy, his wife Malla, and his son Lumpy, though these names were later explained to have been nicknames, their full names being Attichitcuk, Mallatobuck, and Lumpawaroo, respectively.

During the special, scenes also take place in outer space and in spacecraft including the Millennium Falcon and an Imperial Star Destroyer. The variety-show segments and cartoon introduce a few other locales, such as a cantina on the desert planet of Tatooine and a gooey, reddish ocean planet known as Panna.

Luke Skywalker, Han Solo, Chewbacca, Princess Leia are all in there. But their presence absolutely doesn't hide the fact that it is a terrible terrible movie. Episode II is a genius work of art compared to this pile of crap. In it's day the movie received mostly very negative reviews. George Lucas agrees. He said this about the christmas special: "If I had the time and a sledgehammer, I would track down every copy of that show and smash it."

See the special for yourself on YouTube. But I recommend you don't.

To restore your faith in Star Wars watch the trailer of episode VII . Very much looking forward to that one.

https://www.youtube.com/watch?v=wCc2v7izk8w

Read more

Introducing Laravel Spark

Link –

Matt Stauffer wrote another excellent article on Laravel. This time he gives a tour of Laravel Spark.

In case you're still having a bit of trouble understanding what Spark is really about, Spark is a tool designed to make it quicker for you to spin up SaaS applications, and it handles user authentications, plans and payments and coupons, and team logic.

Most SaaSes have these same components: user accounts, Stripe-based payments, and different payment plans. And many have payment coupons and team payment options.

Rather than re-creating this functionality with every new Laravel app you create, just use Spark, and you'll get all that and a free SaaS landing page to boot.

https://mattstauffer.co/blog/introducing-laravel-spark-a-deep-dive

Read more

Using the dataset property in JavaScript

Link –

In plain old JavaScript you can get the data attributes of

[code language="html"]

lorum ipsum
```

like this

[code language="javascript"] document.getElementById('test').getAttribute('data-news-item-id');



But did you know there's a alternative way of doing this by reading an element's dataset property?

[code language="javascript"]
document.getElementById('test').dataset.newsItemId;

Notice that the values can be accessed by camelcasing the name of the data attribute. You can also write to datasets to change values of data attributes. Read the informative helpful article on MDN to know more.

Read more

ActiveRecord and the Beauty Lost in Translation

Link –

If you're going to read one article on ActiveRecord vs Data Mapper let it be this one by Matthew Machuga.

The next time you come across the ActiveRecord vs. Data Mapper argument, or ones like it, be critical of what is being said. If it impacts your work in some way, do some research to find out if what is being said is true or if it has been something lost in translation. Don't feel bad for using a pattern that has spread across multiple languages and ecosystems successfully, and is probably the reason we have most of the web frameworks we do today. While the ActiveRecord existed well before Rails, it was Rails that gave it a beautiful API and made other frameworks like CodeIgniter, Laravel, .NET, Fuel, Django, etc want to have something comparable.

If you use Eloquent, ActiveRecord for Rails, or any other AR ORM, make sure you know that you are not alone. You are in good company of many, many developers who use it successfully day-to-day. However, if one day you choose to use a Data Mapper implementation or something else, then you will still be in good company, and still deserve respect regardless of which side of the fence you fall.

http://matthewmachuga.com/blog/2015/activerecord-and-the-beauty-lost-in-translation.html

Read more

GraphQL: A data query language

Link –

When we built Facebook's mobile applications, we needed a data-fetching API powerful enough to describe all of Facebook, yet simple enough to be easy to learn and use by our product developers. We developed GraphQL three years ago to fill this need. Today it powers hundreds of billions of API calls a day. This year we've begun the process of open-sourcing GraphQL by drafting a specification, releasing a reference implementation, and forming a community around it at graphql.org.
https://code.facebook.com/posts/1691455094417024/graphql-a-data-query-language/

There's already a package to use GraphQL with Laravel.

Read more

A package to add roles and permissions to Laravel

Original – by Freek Van der Herten – 1 minute read

With the release of Laravel 5.1.1 last week the framework gained some nice Authorization features. It provides an easy way to define abilities (aka permissions). Checking if a user has certain abilities is very simple as well. The code powering authorization is a thing of beauty. If you're a…

Read more

Dependency injection with League's new Container

Link –

Jens Segers explains how to use PHP League's shiny new version of Container. The usage of ContainerInterface seems interesting:

League's container now implements the `ContainerInterface`, which is defined by the Container Interoperability group. This is really great as there are a few projects and frameworks which support this interface. For example, the Slim 3 micro framework already allows you to choose your own container flavour, as long as it implements the interface.
Read the full article at Jens' blog.

The League's Container seems like a nice alternative to PHP DI that I have been using.

Read more

Hacking the flow state

Link –

Often, when I’m able to slip into a state of flow while coding, I will produce more in a single afternoon than I could in several days of non-flow. Yet this is often an elusive state to obtain. Luckily, research dedicated to this topic in recent decades offers some help. Here we’ll look into both the stages of flow and how to obtain the prerequisites for flow, making it possible in the first place.

https://medium.com/brigade-engineering/hacking-the-flow-state-b2451d0bf7ba

Read more

A drunk ElePHPant

Link –

Q: What does this code return? date('Y-m-d',strtotime('00-00-00'));

A: 1999-11-30 B: 0001-01-01 C: 2001-01-01

The correct answer is A: 1999-11-30.

You'll find the reasoning behind this result as a comment on this bug report.

There is no bug here, 00-00-00 means 2000-00-00, which is 1999-12-00, which is 1999-11-30. No bug, perfectly normal.

Read more

Using UUIDs with Laravel’s Eloquent ORM

Link –

Garrett St. John wrote a clear example on how to use UUIDs in Eloquent models. This kind of logic could go in a trait so it can be reused across multiple models.

By default, Eloquent uses an auto-incrementing integer as the primary key for its tables. While most of the time this is totally acceptable, sometimes there is a need for primary keys to be less predictable.
http://garrettstjohn.com/entry/using-uuids-laravel-eloquent-orm/

EDIT: Kirk Bushell has made a trait for this functionality. Take a look at his Eloquence package on GitHub.

Read more

The most efficient solution to do non-conditional loops in PHP

Link –

The Retry library by Igor Wiedler has only 19 lines of code. Line 17 is a goto statement. In this issue on GitHub a user asks why Igor chose to use goto instead of resorting to recursion. Igor took the time to write out the reasoning behind that decision. It's a very interesting read on the PHP compiler and opcodes.

Why hello! Thank you for asking this most excellent question!

I have indeed considered alternatives to the goto. I have evaluated them to a great extent, and I am happy to present the results to you here.

https://github.com/igorw/retry/issues/3

Read more

Getting started with Facebook's React.js

Link –

React is a UI library developed at Facebook to facilitate the creation of interactive, stateful & reusable UI components. It is used at Facebook in production, and Instagram.com is written entirely in React.
https://scotch.io/tutorials/learning-react-getting-started-and-concepts

The application I'm currently working will need an advanced search feature that is backed by Algolia. Searches shouldn't hit the application server but use Algolia's JavaScript client. I'm in the process of learning React to build this. The link above was very helpful get started with this new technology.

I'm not ready to blog about my application just yet, but you'll hear more about it as soon as it goes live.

Read more

Pushing polymorphism to the database

Link –

After giving excellent talks at both Laracons, contributing to Laravel's new ACL, putting out an interesting Full Stack Radio episode with Wes Bos, Adam Wathan today published a new screencast. He is now officially on a roll.

After my presentation at Laracon this year, a lot of people asked me how I'd take that same polymorphic approach when the objects would have to be retrieved from the database.

This screencast covers how I'd approach implementing the same idea in a real Laravel application with Eloquent, by using polymorphic relationships and delegation to accomplish the same thing without having to resort to any nasty conditionals.

http://adamwathan.me/2015/09/03/pushing-polymorphism-to-the-database

 

Read more