mardi 28 novembre 2017

Filter data in form request in Laravel 5.5

I have generated new form Request for the controller, but I do not know how to filter data before there will handle in the validator and so on.

Are there some native solutions in Laravel for this case?

class TestRequest extends FormRequest
{

  /**
   * Determine if the user is authorized to make this request.
   *
   * @return bool
   */
  public function authorize()
  {
      return true;
  }

  /**
   * Get the validation rules that apply to the request.
   *
   * @return array
   */
  public function rules()
  { 


    return [
       "title" => "required|string",
       "order" => "required|integer"
    ];
  }

}

class TestController extends Controller
{ 
     public function store(TestRequest $request, $chapterId)
     {
       // some business logic
     }
}

There is some solution in Laravel 5.5 but in this example author uses validate for filtering data from request, but I need to use filter inside TestRequest

 $data = $this->validate(request(), [
         //...
    ]); // I can't use this inside TestRequest



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2zM0rcb
via IFTTT

Aucun commentaire:

Enregistrer un commentaire