By default in Laravel there are two middlewares, which sanitize input data App\Http\Middleware\TrimStrings and Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull. Their names speak for themselves. These middlewares sanitize all input data of every request. But what if we need to sanitize only several fields of concrete request? Well, possible solution is to place sanitize logic in prepareForValidation method of our custom Request class, which extends Illuminate\Foundation\Http\FormRequest.


namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

abstract class Request extends FormRequest
* Sanitize request data before validation.
protected function prepareForValidation()
// Dummy example.
// Warning! User input data will be modified!
$this->replace(['amount' => (int)$this->input('amount')]);

Laravel provides us an easy way to add our custom validation rules. According to documentation, all you need to do is to call extend method on Validator facade in AppServiceProvider boot method.

Validator::extend('foo', function ($attribute, $value, $parameters, $validator) {
return $value == 'foo';

But what if you want to use existing methods for validation, which are used by Laravel Validator class? For example, you need to validate that field under validation is valid email address and it is less than ten characters length (according to project business logic)? You can write the following rule in your form request class.

In this post I’d like to introduce yet another solution for zero time deployment of laravel project. My solution is based on ansible. Ansible is an open-source automation engine that automates software provisioning, configuration management, and application deployment.

Suppose you recently created fresh droplet on with Ubuntu 16.04. To run new website on this server you need to do many things:

  • add new user, grant him sudo access
  • configure sshd: prevent root login, disable password authentication
  • configure iptables and fail2ban
  • configure automatic security updates
  • configure timezone
  • install php, nginx, mysql
  • install ssl sertificate
  • create swap file

To make life…

Why may you want to use Laravel Dusk with Selenium and Firefox instead of default Chrome driver?

For the most use cases you don’t want to use Laravel Dusk with Selenium and Firefox. Because Chrome driver is much faster and it does not depend on Selenium.

The reason I use Laravel Dusk with Selenium and Firefox is capability to configure Firefox plugins right from your Dusk setup code. For example, you need to pass additional headers when you visit some site. You cannot do this right from your script, because Selenium API do not have methods for it (it is…

Alexander Melihov

Freelance fullstack Laravel web developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store