Validating the file upload

With all the previous work in place for the file upload, now I want to cover file validation. For this, we will let the Laravel request method handle the logic for us. This way, we can deal with all of this outside the controller, so when we plug it in we will be ready to go. I will cover checking file size and type.

Getting ready

Use the previous recipe to set up sound groundwork. I will use that recipe to then create a test around size and type of file.

How to do it…

  1. Make the custom form validation request:
    >php artisan make:request ProfileUploadRequest
  2. Now add to our Behat feature features/profile/profile_image.feature some of the things we are looking for:
  3. Then we run the step in the following image to stub out our steps ...

Get Laravel 5.x Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.