Deploying Laravel via Ansible

Fast and easy solution for automatic deployment of Laravel project using Ansible.

There are lots of different ways to deploy you code to production server. Some have bash scripts, others use deployment tools such as Capistrano or Deployer. I’ve even saw people who build deb/rpm packages with their projects and install them directly to servers from custom repositories.

Here I want to present you another solution that is made right for Laravel project and uses Ansible.

Read More

Email templates optimization for Laravel

Optimize your email templates’ styles via native Laravel templating mechanism.

If you want to send an HTML email you can’t just send it with <style></style> tag in it, or link a stylesheet. Most of the email clients will cut it and clients will see your email without any styles.

The only approach to achieve best email quality is to convert all your styles int inline style="" attributes.

Read More

API Exceptions for Laravel

All in one solution for exception for JSON REST APIs on Laravel and Lumen.

About

The goal of this package is to provide you with a set of most common exceptions that may be needed while developing JSON REST API. It also:

  • Handles exceptions output.
  • Handles exceptions report to logs.
  • Overwrites default Validator to make validation errors more verbose.
  • Has a FormRequest that to handle validation errors and pass them to ApiExceptions layer.
  • Has middleware to catch all system errors such us RuntimeExceptions or ModelNotFoundException to handle them and threat as normal ApiExceptions.

Read More

Load Your JavaScript Library Asynchronously

Lets imagine, we have a common page:

<!DOCTYPE html>
<html>
  <head>
    <script src="app.js"></script>
    <script>
      App.init('greeting', 'Hello, John Doe!');
    </script>
  </head>
  <body>
    <h1 id="greeting"></h1>
  </body>
</html>

With javascript library included:

// app.js
var App = {
  /**
   * Handle already registered actions.
   *
   * @param  {String} id   Element ID
   * @param  {String} name User's name
   */
  init: function (id, name) {
    document.getElementById(id).text(name);
  }
}

Read More

Add handy setup wizard to your Laravel project

Imagine that you distribute your Laravel project. It is awesome, useful and remarkable. But every time your customer installs it, he has to perform a set of steps to setup it: add .env file, run migrations and seed, etc. And you have to mention them all in your README and hope that user will do everything right. But why not to guide your customer through all this steps with one simple command?

All you have to do is to add Laravel-Setup-Wizard package to your project!

setup

Read More

Laravel + Hashids

Everyone nowadays used youtube or any short link creator. If you look to the links they use (eg. https://youtu.be/qatmJtIJAPw) you will notice that they use unique string hashes instead of common auto-increment ids. They do it because anyone can just iterate ids and get access to all their content. And of course they don’t want it.

If you want to protect your content too, you have to replace your ids with hashes. There are lots of tools that can convert integers to unique hash ids. They work practically identically, and I will show how to integrate one of them Hashids with Laravel.

There are lots of packages that already integrate Hashids into Laravel, but they only add it’s facade and give some syntactic sugar. But we need complex integration with easy model binding and all logic under the hood! So let’s do the magic!

Read More

Extend your Laravel Seeder

Laravel brings you awesome seeding functionality. But it is not as perfect as it could be. By default Laravel Seeder was made to store random data (it even suggests you to use Faker package). But what will you do if you have lots of data that already exists in my DB? There are several ways to achieve this. You can import raw arrays, SQL data, or use CSV files. I choose the third approach because CSV files are easier to edit. That’s why I created a Laravel-Extend-Seeder package that implements this method.

Read More