fredyounan
11/15/2014 - 9:57 AM

Remove null values from the Laravel only method This class should extend the core Request class http://laravel.com/docs/extending#request-ex

Remove null values from the Laravel only method This class should extend the core Request class http://laravel.com/docs/extending#request-extension Application::requestClass('Foo\Request');

<?php

/**
 * Remove null values from the Laravel only method
 * 
 * This class should extend the core Request class
 * http://laravel.com/docs/extending#request-extension
 *
 * Application::requestClass('Foo\Request');
 */

namespace Foo;

class Request extends \Illuminate\Http\Request {

	/**
	 * Removes null values from the only method
	 * @param array $keys
	 * @return array
	 */
	public function only($keys)
	{
		$keys = is_array($keys) ? $keys : func_get_args();
		
		$arr = parent::only($keys);

		return array_filter($arr, function($value)
		{
			return ($value !== null);
		});
	}
}