Support the ongoing development of Laravel.io →
Requests Validation
Last updated 2 years ago.
0

check out Filters

0

Sounds really useful.

I did some googling for my own benefit, and it looks like in Laravel 5, there is no longer a concept of filters - this is now acheived using middleware.

Though the 5.0 source does have Controller::before:

// vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php

/**
 * Call the "before" filters for the controller.
 *
 * @param  \Illuminate\Routing\Controller  $instance
 * @param  \Illuminate\Routing\Route  $route
 * @param  \Illuminate\Http\Request  $request
 * @param  string  $method
 * @return mixed
 */
protected function before($instance, $route, $request, $method)
{
	foreach ($instance->getBeforeFilters() as $filter)
	{
		if ($this->filterApplies($filter, $request, $method))
		{
			// Here we will just check if the filter applies. If it does we will call the filter
			// and return the responses if it isn't null. If it is null, we will keep hitting
			// them until we get a response or are finished iterating through this filters.
			$response = $this->callFilter($filter, $route, $request);

			if ( ! is_null($response)) return $response;
		}
	}
}

Any ideas what that does?

There is no mention of this in the Laravel 5.0 docs.

(I wish Laravel had more complete docs; the generated API resource is severly lacking)

Last updated 9 years ago.
0

Or write your own utility class and include it with a use statement at top of controller, that will allow you to do things like format dates and other useful things.

0

Validate the date in the format you get from input and convert it after. Unless you have a really good reason not to.

0

I think @mengidd is right. Validate the data first then convert after. With this, you are sure that you are only converting valid dates.

@davestewart: I think that method is called by the middlewares or that is responsible when calling your middlewares.

Last updated 9 years ago.
0

relevant https://laracasts.com/discuss/channels/general-discussion/laravel-5-modify-input-before-validation

The easiest way is to just override the 'all()' function in your request, whatever you return will be whats passed to the validator see Illuminate\Foundation\Http\FormRequest@getValidatorInstance

class CreateJob extends Request {

	public function authorize()
	{
		return true;
	}

	public function rules()
	{
		return [
			//validation rules
		];
	}

	public function all()
	{
		$input = parent::all();

		//modify input here

		return $input;
	}
	
}

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.