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.

Some Laravel Homestead tips

Link –

Homestead is a pre-packaged Vagrant box that includes a good development environment. It was made and is maintained by Taylor Otwell, the creator of Laravel. In this post I'd like to share some tips regarding this box.

Map all sites at once

For every project a directory needs to be mapped from the host to the guest in folders-section of the yaml file. Let's make that a bit easier. Instead of adding a specific project to the folders-section you can add the folder where all projects reside in. I personally store all sites I'm working on in the `~/dev/sites` folder. So by adding that folder to the yaml file, no new mappings are needed when creating a new site.
folders:
    - map: ~/dev/sites
      to: /home/vagrant/sites

Avoid having to edit the hosts file

When adding a site to homestead you have to map an url to a public folder in the sites-section of the yaml-file. To make this work the url should be pointed to the ip address of the homestead box by adding it to your hosts file:.
192.168.10.10 url-to-your-homested-project.com  #default ip of the homestead box

You can avoid having to edit the hosts file by using a xip.io-url. Xip.io is a special domain created by Basecamp. The nameserver of that domain will resolve all urls to the ip-address that is specified inside the url. For example: "myproject.192.168.10.10.xip.io" will resolve to 192.168.10.10. If you use such an url in your homestead configuration there's no need to edit your hosts file.

sites
    - map: spatie.192.168.10.10.xip.io #no need to put this url in your hosts file
      to: /home/vagrant/sites/spatie.be/public

The downside of using a xip.io-url is that such url's are quite long. This can be improved by installing a local dns server. The local dns server will resolve all lookups of a given top level domain to the ip address of the homestead box. Here's a nice article that explains how to resolve all *.dev requests to a specified ip adress.

On OSX these steps can be used to install and configure dnsmasq to point all *.dev requests to homestead.

# Install dnsmasq
brew install dnsmasq
# Copy the default configuration file.
cp $(brew list dnsmasq | grep /dnsmasq.conf.example$) /usr/local/etc/dnsmasq.conf

# Copy the daemon configuration file into place.
sudo cp $(brew list dnsmasq | grep /homebrew.mxcl.dnsmasq.plist$) /Library/LaunchDaemons/

# Start Dnsmasq automatically.
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
echo "address=/dev/192.168.10.10" >> /usr/local/etc/dnsmasq.conf

#restart dnsmaq
sudo launchctl stop homebrew.mxcl.dnsmasq
sudo launchctl start homebrew.mxcl.dnsmasq

#make osx use dnsmasq
sudo mkdir -p /etc/resolver
sudo tee /etc/resolver/dev >/dev/null <<EOF
nameserver 127.0.0.1
EOF

After performing these steps you need to restart your mac. If you know some better way to active dnsmasq besides rebooting, let me know.

When your mac comes back up try pinging a random .dev domain.

Screen Shot 2016-01-13 at 21.24.30 With dnsmasq up and running you can .dev domains can be used in the homestead yaml file:

sites
    - map: spatie.dev #no need to put this url in your hosts file
      to: /home/vagrant/sites/spatie.be/public

Use a bash function to work with a globally installed homestead

You can opt to use a seperate homestead box for every project. I personally prefer one homestead box for all projects. In the Laravel 4.2 days the Laravel documentation covered a PHP tool to easily work with a homestead box. This section has been removed in the 5.X documentation, so I assume that development of the tool has been stopped. Fortunately all functionality that the PHP tool provided can be performed by this small bash function:
function vm() {
   cd ~/homestead
   
   command="$1"

   if [ "$command" = "edit" ]; then
      open ~/.homestead/homestead.yaml
   else
      if [ -z "$command" ]; then 
         command="ssh"
      fi
   
      eval "vagrant ${command}"
   fi

   #switch back to directory where command was performed in
   cd -
}

When this function is loaded these commands can be executed from every directory.

  • `vm up`: start the homestead machine
  • `vm halt`: stop the homestead machine
  • `vm`: ssh into the homestead machine
  • `vm edit`: edit the yaml file in the default text editor
  • `vm provision`: provision the homestead machine

Map your dotfiles directory

Terminal users often save their most used functions, aliases and general configuration in a dotfiles repository. This dotfiles-directory is generally cloned in the home folder on a development machine. When that directory is mapped to homestead as well the custom functions and aliases can be used from inside homestead.
folders
    - map: ~/.dotfiles
      to: /home/vagrant/.dotfiles

Syncing the folder is not enough. The steps you need to perform to load the dotfiles on the host machine should be executed in homestead as well. In case of my dotfiles, the minimum that should be done is symlinking the .zshrc-file

ln -s $HOME/.dotfiles/shell/.zshrc $HOME/.zshrc

This is the result when using my dotfiles: [caption id="attachment_1937" align="alignnone" width="1224"]My custom zsh promt is visible inside homestead. The "a"-alias (short for "php artisan" is working) My custom zsh promt is visible inside homestead. The "a"-alias (short for "php artisan" is working)[/caption]

Do you have some homestead tips to share? Let me know in the comments below.

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.

Reducing complexity

Link –

Matthias Noback, author of "Principles of Package Design", published the first article in a new series on programming best practices on the iBuildings blog. The subject of the first article is reducing complexity.

Inside your method or function bodies, reduce complexity as much as possible. A lower complexity leads to a lower mental burden for anyone who reads the code. Therefore, it will also reduce the number of misunderstandings about how the code works, how it can be modified, or how it should be fixed.
https://www.ibuildings.nl/blog/2016/01/programming-guidelines-php-developers-part-1-reducing-complexity

Read more

Why we are sponsering our local user group

Original – by Freek Van der Herten – 3 minute read

At the end of this month our local user group, PHP Antwerp, will hold it's third meetup. It'll be sponsered by Spatie, of which I'm a co-owner. In this post I'd like to explain why we are sponsering this event. Of course as a company it's good to get our name out there but there are other more…

Read more

The innovation slider

Link –

Konstantin Kudryashov shares some thoughts on the relation between predictability and innovation.

Every time I meet a client to discuss their new project plans, I encounter the same question: "I want my software to be unique and different. How much will it cost?” The problem is that unique products and true innovation are difficult to estimate, and even harder to accurately budget for. Helping a business find the balance between the innovation they need, and the predictability they want led me to create the Innovation Slider, a tool you can use to harmonise the split between innovation and predictability in software projects.
http://stakeholderwhisperer.com/posts/2016/1/innovation-slider

Read more

Say goodbye to manually creating a robots.txt file

Original – by Freek Van der Herten – 1 minute read

If you don't want a site to be indexed by search engines you must place a robots.txt file. Typically you don't want anything indexed except production sites. Today Spatie released a new package called laravel-robots-middleware. It was coded up by my colleague Sebastian. Instead of you having to…

Read more

Why we are requiring PHP 7 for our new packages

Link –

The past few weeks we released several new packages: laravel-sluggable, laravel-robots-middleware, laravel-glide and pdf-to-text. These packages have in common that they all require PHP 7. Because there were several reactions and questions about this, I'd like to shed some light on that decision.

I expect that lots of developers will make the move to PHP 7 in the coming year. Sure there will always be legacy projects that'll never see an upgrade, but it makes no sense starting a greenfield project in PHP 5.X. The performance benefits are just too good. On the package side I expect that some widely used packages will make the jump as well. Jordi Boggiano has already announced that the next version of Monolog targets PHP 7. Also keep in mind that active support for PHP 5.x is coming to end this August (or at the latest December).

Not only developers will make a quick move to PHP 7. The speed benefit is quite interesting for hosting companies as well. A speedier PHP version means a machine can host more sites. There quite a few hosting companies that already made the jump and are offering PHP 7 support.

When we work on projects at Spatie we have to solve a lot of problems. When we solve a problem in way that the solution can be used in future projects, we create a package. So we create these packages primarily for our own future projects. We decided that from now on every greenfield project wil be a PHP 7 one. So it makes sense that our new packages would require PHP 7 as well. By doing so we can make use of the latest new features such as the scalar type hints, return types, anonymous classes and the null coalescing operator. At some point all our projects will leave PHP 5.6 behind. The earlier we won't have to deal with PHP 5.X code anymore the better.

I'm well aware that requiring PHP 7 will hurt the popularity of our packages in the short run. But popularity is not our main goal. People who are using the latest and greatest version of PHP can benefit from our work. And I hope others will be nudged a bit towards PHP 7 by our decision.

(EDIT: we won't change the requirements of our older packages. PHP 7 will only be required when we create a new major version.)

Read more

A package to extract text from a pdf

Original – by Freek Van der Herten – 1 minute read

For a project I needed to extract some text from a pdf. Although there were already a few packages that could to this, I still created spatie/pdf-to-text because I wanted something that was really easy to use. And also because it's fun creating packages. Under the hood a utility called pdftotext is…

Read more

A beginner’s guide to information architecture

Link –

... information architecture is the creation of a structure for a website, application, or other project, that allows us to understand where we are as users, and where the information we want is in relation to our position. Information architecture results in the creation of site maps, hierarchies, categorizations, navigation, and metadata.

Information architecture is a task often shared by designers, developers, and content strategists. But regardless of who takes on the task, IA is a field of its own, with influences, tools, and resources that are worth investigation. In this article we’ll discuss what information architecture really is, and why it’s a valuable aspect of the user experience process.

http://www.uxbooth.com/articles/complete-beginners-guide-to-information-architecture/

Read more

Starting a newsletter

Original – by Freek Van der Herten – 1 minute read

I decided to add a newsletter to my blog. The plan is to send out a newsletter every two weeks. Newsletters will contain lots of interesting stuff for the modern PHP developer. You can expect quick tips, links to interesting tutorials, opinions and packages. Because I work with Laravel every day…

Read more

Vim for beginners

Link –

Last year I made myself a bit acquainted with Vim. I'm by no means an expert and am not (yet :-)) advocating to replace your favourite IDE with Vim. I use it for small things:

  • it's much easier/faster to to edit files on a server using Vim as opposed to opening and editing the files in a tool like Transmit. There's a big chance that vim is already installed on your server.
  • editing your hostfile is breeze with vim.
  • if you need a small change, like deleting a line, in a file and you're IDE isn't open, Vim can help you.
  • there's a big change that you already use Vim when Git promts you to specify a commit message
Unlike most pieces of software, Vim has absolutely no respect for the beginner. Even quitting it proves quite difficult. There's really nobody that can use Vim without some training. But with same quick pointers everybody can do the tasks mentioned above.

Watch this video clearly explains the basic commands.

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

Read more

How to become a great engineer

Link –

Philip Walton, an engineer at Google, wrote a wonderful article that every developer should read. He talks about front-end engineers, but most tips are applicable to back-end engineers as well. A few quotes:

Taking the time to figure out why your hack works may seem costly now, but I promise it’ll save you time in the future. Having a fuller understanding of the systems you’re working within will mean less guess-and-check work going forward.
Solving problems on your own is a great way to learn, but if that’s all you ever do, you’ll plateau pretty quickly. Reading other people’s code opens your mind to new ways of doing things.
In my experience, writing, giving talks, and creating demos has been one of the best ways to force myself to dive in and fully understand something, inside and out. Even if no one ever reads what you write, the process of doing it is more than worth it.
Be sure to read the full article here: http://philipwalton.com/articles/how-to-become-a-great-front-end-engineer/

Read more

Easily convert images with Glide

Link –

Glide is an easy to use image manipulation library by Jonathan Reinink. It was bumped to version 1.0.0 a few days ago. Glide can created optimized images on the fly by levering url's such as /img/users/1.jpg?w=300&h=400&fit=crop. Take a look at the example in the Glide documentation to know more.

I think Glide provides a very nice API to create image manipulations. Unfortunately it isn't very easy to use the API to generate an image using code. So I created a little package for that called laravel-glide. All new major versions of Spatie packages will require PHP 7, laravel-glide is no exception to this.

Here's an example of how to create a greyscale version image with a maximum width of 50 pixels.

GlideImage::create($pathToImage)
    ->modify(['filt'=>'greyscale', 'w'=> 50])
    ->save($pathToWhereToSaveTheManipulatedImage);

Take a look at Glide's image API to see which parameters you can pass to the modify-method.

Read more

The Road to Monolog 2.0

Link –

One of the main questions when doing a major release is which minimum PHP version to support going forward. Last summer I decided I wanted to do a big jump from 5.3 and directly target PHP 7. It provides a lot of nice features as well as performance improvements, and as Monolog is one of the most installed packages on Packagist I wanted to help nudge everyone towards PHP 7.
http://seld.be/notes/the-road-to-monolog-2-0

Read more

Shaping your technical patterns based on your organizational patterns

Link –

Most outlets of technical information (whether high profile developers, companies, etc…) focus on architectural patterns and there’s never any talk about organizational patterns. In other words, does the architectural pattern that you choose fit your organizational pattern?
http://eli4d.com/2015/12/23/fullstack-radio-podcast-episode-with-dhh-shaping-your-technical-patterns-based-on-your-organizational-patterns/

Read more

A PHP 7 / Laravel package to create slugs

Original – by Freek Van der Herten – 2 minute read

Spatie, the company where I work, recently released a Laravel package called laravel-sluggable. It automatically creates unique slugs when saving a model. To install the package you just need to put the provided Spatie\Sluggable\HasSlug-trait on all models that have slugs. The trait contains an…

Read more

Converting big PHP codebases to PSR-2

Link –

It is known by now that every codebase large enough (in terms of lines of code or people collaborating to it) should follow any code standard. Here at Coolblue we weren’t different and were using our own coding standard.

But codebases evolve. And our codebase – that has been supporting one of the most visited ecommerces in The Netherlands – needed to be upgraded to a coding standard that’s a little bit more up to date.

This is the process we follow to move into PSR-2.

http://devblog.coolblue.nl/tech/converting-big-php-codebases-to-psr2/

In the past months we converted several of our old projects to PSR-2 with Fabien Potencier's coding standards fixer and had zero issues doing so. Hurray for standardized code.

 

Read more