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.

How (not) to use accessors in Eloquent

Link –

Jarek Tkaczyk wrote a blogpost on the usage of accessors in Eloquent. He demonstrates what could go wrong when using accessors on certain fields.

The moral of the story is, that data handling and its presentation should not go into the same bucket. And the model is that bucket – instead of creating accessors, traits or god knows what for this task, better use decorator (like) pattern where you can do all the necessary work for preparing your data to be displayed in your view, without touching actual values anywhere else.

https://softonsofa.com/they-can-bite-how-not-to-use-accessors-in-eloquent/

Keep this in mind when you should use my pragmatic approach for presenters. Watch out for conflicting names.

Read more

Simplifying presenters in Laravel

Original – by Freek Van der Herten – 3 minute read

In the Laravel template that we use to kickstart all our client projects at Spatie, I recently changed the way we handle presenters. Instead of using Jeffrey Way's popular presenter package we now use simple traits. In this post I want to give some background on that change. In case you've never…

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.

Taking care of backups with Laravel

Original – by Freek Van der Herten – 8 minute read

A new major version of laravel-backup was recently tagged. This package can backup files and databases of your Laravel app (or any PHP application really). The backup consists of a zipfile containing a dump of the databases and all files that are selected for backup. The package will copy over the…

Read more

A retrospective on creating Laravel Shift

Link –

Laravel Shift is a paid service that can upgrade a Laravel project. I've used it a couple of times. Although some manually work is needed to complete the upgrade, it has saved me many hours. The service has recently shifted it's 1000th project, a major milestone. In a post on his blog Jason shares how he started the service and where it's going in the future.

In this post, I want to focus more on reaching the milestone of 1,000 Laravel applications upgraded. This may not sound like many, however for my first SaaS product it marks the achievement of my stretch goal. So allow me to share the most important decision, biggest challenge, and what the future holds for Laravel Shift.

http://jason.pureconcepts.net/2016/09/laravel-shift-1000-applications-upgraded/

Read more

How to design words

Link –

John Saito, a designer at Dropbox, wrote down some very useful tips to improve the text in your UI.

Technically speaking, I’m a writer. I get paid to write words. But here’s something most people don’t know about me: I hate to read. ... You see, I mostly write interface text for apps and websites. It’s a style of writing where brevity beats brilliance, and every character counts. Writing interface text is actually a lot like design—designing words for people who hate to read.

https://medium.com/@jsaito/how-to-design-words-63d6965051e9

Read more

Is your JavaScript function actually pure

Link –

What does “pure function” mean in the context of JavaScript? In programming in general, purity is also known as “referential transparency”, a fancy way of saying “replacing an expression or function call with its result will never change the behavior of the program” or a way of saying “every time you pass the same inputs, you always get the same outputs”.

That sounds intuitive, and a function like x => x * 10 looks pure because every single time you pass it the number 3 as argument you will get 30 as output. So how can we tell that one function is pure and the other isn’t? Is it enough that we just read the code?

Spoiler: reading the code isn't enough.

http://staltz.com/is-your-javascript-function-actually-pure.html

Read more

Advancing in the Bash Shell

Link –

If you want to learn some neat bash tricks, read this excellent read by Sam Rowe.

If you’ve ever used GNU/Linux, chances are good that you’ve used bash. Some people hold the belief that using a GUI is faster than using a CLI. These people have obviously never seen someone who uses a shell proficiently. In this tutorial, I hope to show you just a few of the amazing features bash provides that will increase your productivity in the shell.

http://samrowe.com/wordpress/advancing-in-the-bash-shell/

Read more

Building a search engine friendly sitemap XML with Laravel

Link –

Eric Barnes of Laravel News wrote a good tutorial on how to create a sitemap with Laravel.

A few years ago search engines recommended submitted sitemaps to help with indexing your website and now the importance of this is debatable.

I’m of the mindset creating and submitting can’t hurt, so I spent a little time putting one together and wanted to share how easy this is in Laravel.

https://laravel-news.com/2016/09/laravel-sitemap/

Read more

Changes to the type system in PHP 7.1

Link –

PHP 7.1 is nearing completion. A few days ago Release Candidate 1 was released. One of the areas that got some love from the developers is the type system. Pascal Martin wrote a blogpost about those changes.

One of the most important changes PHP 7.0 brought us last year was about typing, with the introduction of scalar type-declarations for functions/methods parameters and their return value. PHP 7.1 adds to those type-declarations, with several points that were missing in the previous version of the language.

https://blog.pascal-martin.fr/post/php71-en-types.html

That new iterable pseudo-type will sure come in handy.

If you want to know what's changed regarding error handling, Pascal has got that covered as well.

Read more

How to create a most popular list with Laravel and Google Analytics

Link –

Over at Laravel News Eric L. Barnes posted a new tutorial on how he used our Analytics package to create a list of most popular posts. Great stuff!

Here on Laravel News, I wanted to generate a list of the most popular posts for the past seven days and display the results from most popular to least popular.

To solve this problem I thought of two solutions. The first is to build my own tracking system so I could keep a count and then use it for ordering. However, that could generate a huge amount of data and it seemed like a solution that an analytics tracking service could handle.

As I was fumbling through the Google Analytics API I found a Laravel Analytics package by Spatie.be that allows you to easily retrieve data from your Google Analytics account and it seemed like the best way to solve this problem. Let’s look at how I used it to generate a list of popular posts here on Laravel News.

https://laravel-news.com/2016/09/most-popular-list-laravel-google-analytics/

Read more

Hacking a PHP site

Link –

In the beginning of the summer the Belgian company PHPro held a cool hacking contest. The persons the could hack a special site that they had set up could win a prize. Yesterday they published an interesting article on how that site could be hacked. The site was also hacked in ways that the developers of the company did not anticipate.

Since this contest started out as an internal project, we've put a lot of focus on the flow on how to hack the website. It was just a little side project to inform our colleagues that some small mistakes can end up in a big catastrophe. By focussing on the flow of the hackme contest, we forgot to secure the application for malicious contestants. Off course, this was something that fired back to us on the first days of the competition. Here is a little write-up of the problems we've encountered and how we fixed them.

http://phpro.be/news/hackme-results

Read more

Fixing Laravel Valet on macOS Sierra

Link –

I'm one of those people who runs beta software. A short time after the keynote is finished I'll update (or wreck) my phone with the beta version of iOS. My Mac generally gets the beta treatment not much later. Of course there are some risks involved. There's no guarantee that your applications will still work. Though your mileage may vary, it's my experience however that those betas are pretty stable.

With macOS Sierra there was one piece of software that didn't work properly: Laravel Valet. For some obscure reason Valet just stopped working after a couple minutes. The requests just hang. After some time an ERR_CONNECTION_REFUSED was displayed in Chrome. After running valet restart it ran fine for some more minutes. After poking around in the configuration of caddy, the webserver that powers Valet, and the php.ini file I found no solution. A complete reinstall of Laravel Valet did not solve the issue. I learned to live with the problem, regularly running valet restart. I even set up an alias for it.

But luckily Bryce Adams found the solution (Martin Bastien notified me about it). It's very simple: you just have to update the caddy server to the latest version manually. Here are the steps involved:

  1. Download `caddy_darwin_amd64.zip` from Caddy's releases page on GitHub.
  2. Extract the files and rename the main executable `caddy_darwin_amd64.zip` to `caddy`
  3. Copy it over and replace the old `caddy` file in this directory: `~/.composer/vendor/laravel/valet/bin/`
  4. Run `valet restart`
  5. Profit!

I hope this post can help all the crazy ones running beta software.


EDIT on 2016-09-21: alternatively, you could use the dev-sierra branch to get a working version of Valet on macOS Sierra.

EDIT on 2016-09-24: Adam has published a list of common problems and solutions for running Valet on Sierra.

Read more

A package to sync your .env file with .env.example

Link –

In a Laravel app most sensitive configuration values, like a db password, are being saved in an .env file. This file usually does not get committed in a git repo. In this way you can share the repo with collaborators without having them to know the sensitive values of your production environment.

The keys of the .env are often saved in an .env.example file that is saved in the repo. This helps you and your collaborators get up to speed quickly when installing the app locally. They can immediately see which environment variables are needed to run the app.

Over time however you might add a variable to .env and forgetting to add it to .env.example. It's a mistake that is easily made, and I have made that mistake many times in the past (sorry co-workers).

A couple of days ago Julien Tant released laravel-env-sync. This package makes sure the .env file is in sync with .env.example. After having installed the package you can run this artisan command to perform the sync:

php artisan env:sync

Thanks Julien for that awesome little package.

Read more

Our dashboard has been updated to make use of Laravel Echo

Original – by Freek Van der Herten – 1 minute read

A couple of months ago we released a dashboard powered by Laravel, Pusher and Vue.js. In tandem with Laravel 5.3 a new JavaScript library was released called Laravel Echo. This library makes it very easy to work with a service like Pusher. This weekend I took the time to update the dashboard to make…

Read more

Automatically generate a sitemap in Laravel

Original – by Freek Van der Herten – 7 minute read

Today my company released a package called laravel-sitemap. There are already a lot of excellent sitemap packages out there. They all have in common that you have to manually add links that must appear in the sitemap. With our new package that isn't required. It can automatically build up a sitemap…

Read more

Hunting for great names in programming

Link –

A great story by DHH on his quest to find good names for some functions he was working on.

One of the real delights of programming is picking great variable, method, and class names. But an even greater treat is when you can name pairs, or even whole narratives, that fit just right. And the very best of those is when you’re forced to trade off multiple forces pulling in different directions.

https://m.signalvnoise.com/hunting-for-great-names-in-programming-16f624c8fc03

Read more