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)
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.
Validate the date in the format you get from input and convert it after. Unless you have a really good reason not to.
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.
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;
}
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community