PHPackages                             bluecode/laravel-nullable-field - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bluecode/laravel-nullable-field

ActiveUtility[Utility &amp; Helpers](/categories/utility)

bluecode/laravel-nullable-field
===============================

This trait allows you to easily flag attributes that should be set as null.

27PHP

Since Nov 5Pushed 10y ago1 watchersCompare

[ Source](https://github.com/matmaxanh/laravel-nullable-field)[ Packagist](https://packagist.org/packages/bluecode/laravel-nullable-field)[ RSS](/packages/bluecode-laravel-nullable-field/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Nullable database fields for Laravel
====================================

[](#nullable-database-fields-for-laravel)

Often times, database fields that are not assigned values are defaulted to `null`. This is particularly important when creating records with foreign key constraints.

Note, the database field must be configured to allow null.

More recent versions of MySQL will convert the value to an empty string if the field is not configured to allow null. Be aware that older versions may actually return an error.

Laravel (5.1) does not currently support automatically setting nullable database fields as `null` when the value assigned to a given attribute is empty.

Installation
============

[](#installation)

This trait is installed via [Composer](http://getcomposer.org/). To install, simply add it to your `composer.json` file:

```
{
	"require": {
		"bluecode/laravel-nullable-field": "~0.1"
	}
}

```

Then run composer to update your dependencies:

```
$ composer update

```

In order to use this trait, import it in your Eloquent model, then set the protected `$nullable` property as an array of fields you would like to be saved as `null` when empty.

```
