Conditional validation on Laravel's Form Request

Introduction

In my opinion, Laravel Form Requests are one of the most useful components of Laravel. They can perform authorization and validation on requests, without even touching the controller.

Form Requests are also very flexible, because they are completely customizable by method overriding.

When creating a Form Request, the first method to implement is the authorization() method, which can be used to check if the authenticated user can perform the action. For example the following …

Read More
Confirm form submission without loops using jQuery

Introduction

This post falls in the category “Short tricks that I would teach to my younger self”.

Let’s assume that you want to display a confirmation dialog before submitting an important form. You can leverage the Window.confirm() method, which displays a modal dialog with two buttons, Ok and cancel.

Window.confirm() returns true if the user clicks on the Ok button.

<form onsubmit="return confirm('Do you really want to submit the form?');">

You …

Read More
Check for foreign key existence in migrations

Laravel provides a couple of handy features to check for the existence of a table or column using the hasTable and hasColumn methods:

<?php

if (Schema::hasTable('users')) {
    //
}

if (Schema::hasColumn('users', 'email')) {
    //
}

However, sometimes you need to check the existence of foreign keys or indexes on tables, for example when you need to rename columns, in order to avoid annoying errors. Unfortunately Laravel doesn’t provide such methods out of …

Read More
Integrate the Facebook SDK in a React Native application

Introduction

React Native FBSDK is a wrapper around the iOS and Android Facebook SDK which allows for Facebook integration in React Native apps. It allows to access to native components, from login to sharing, entirely through documented JavaScript modules so you don’t have to call a single native function directly.

I thought that setting it up would be quite simple but unfortunately I was wrong! It is a little bit complicated to get it running and you have to figure out by yourself …

Read More
Array Validation in Laravel 4

Introduction

At work we are still using Laravel 4 for a few projects. From time to time we need to validate an array of form fields using the Laravel Validator, however before Laravel 5.2 this was not a trivial task. Let’s break down the problem a little bit.

Suppose that you want to validate a form that uses dynamic fields, added at run time by the user. Take the example of a product in an ecommerce website. We need to insert some information on a product, let’s say the name, …

Read More
Basic ProcessWire website workflow - Part Four

Introduction

Following Part 1, Part 2 and Part 3.

In this post we will make the final touches and personalizations to our website. Let’s see what are going to do:

  • Implement a basic Sitemap
  • Implement ProcessWire Roles and Permissions
  • Tweak CKEditor a little bit
  • Implement a little countermeasure to avoid bots to read emails
  • Implement the Facebook plugin
  • Add the cookie notification

Also this post concludes this series on ProcessWire, but don’t worry, I’m planning to write …

Read More