Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Laravel 5.x Cookbook

You're reading from  Laravel 5.x Cookbook

Product type Book
Published in Sep 2016
Publisher Packt
ISBN-13 9781786462084
Pages 402 pages
Edition 1st Edition
Languages
Authors (2):
Terry Matula Terry Matula
Profile icon Terry Matula
Alfred Nutile Alfred Nutile
Profile icon Alfred Nutile
View More author details

Table of Contents (17) Chapters

Laravel 5.x Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
1. Setting Up and Installing Laravel 2. Using Composer Packages 3. Routing 4. Building Views and Adding Style 5. Working with Data 6. Adding Angular to Your App 7. Authentication, Security, and Subscriptions 8. Testing and Debugging Your Application 9. Adding Advanced Features to Your App 10. Deploying Your App Index

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 in the context file. This is due to the --append-snippets switch:

    And we are set to start writing the code needed to handle this!

  4. Our test will look like this as it verifies the file type, in this case, I pass in png but in my form request I set...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}