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.

<?php

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')]);
}
}

Of course we want apply the same sanitize logic to some other fields. …


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.

public function rules()…


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 digitalocean.com with Ubuntu 16.04. To run new website on this server you need to do many things:

  • 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 easier I created repository, which contains ansible playbook to do all the things listed above. …

About

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