Laravel 5.8 – From The Ground Up - Laravel 5.8 Tutorial From Scratch – e09 – Form Validation

Education, Programming

Laravel 5.8 – From The Ground Up

52 Lessons

Laravel 5.8 Tutorial From Scratch – e09 – Form Validation

so in the previous episode we kind of ended in a cliffhanger and that was this integrity constraint violation now if you recall all we did was hit the add

new customer button without actually typing anything into our form and as we all know of course that is probably not functionality that you want you want to be able to come back to the user and say

hey you forgot to give us a name give us a name otherwise we're gonna ignore your request so let's dive in and see how we could do this with laravel so let's switch back to phpstorm and right now we

have this customer right here but we are assuming that the request has a name but we haven't really checked that so let's add a new layer of validation here and let's add that here at the top so how do

we validate this request let's say our data is equal to request validate and so inside validate we're gonna pass in an array and this array will tell layer though what it is that we're trying to

validate so the first thing i want to do is validate that the name is required and we do that in this form so name which is the input name right we see that right here so we are validating

that name is required and that's it laravel actually takes care of everything else for us it will actually redirect back it will give us errors we just need to display those so let's give

that a go and see what it does let's go back to Chrome I'm gonna hit refresh and then I'm gonna hit that add customers one more time and here we go now if you look up here closely check out what

happens when I hit the button we see that the page goes out it tries to fetch something happens and then it comes back and of course we see that nothing happened and that is because we are

requiring that field but right now we're not really giving the customer any feedback at all that would be the next step we need to tell them hey you forgot to give us a name go ahead and put your

name in there all right so now let's get these errors to show up so we'll have this errors variable available to us through Lenovo and then we'll say give me the first error for

name and go ahead and display that back in the browser I'm gonna hit refresh one more time and hit add customers and there we go we see the name field is required but I

do see it's kind of down here kind of difficult to see so I'm gonna bring this up and put it right after that and before the button I think that's a better place for it and hit refresh hit

that button one more time and there we go the name field is required now this around that with a div so it makes its own line there we go the name field is required so now we're giving back the

user a little bit of feedback on what it is now another rule that you may have is that it needs to be at least three characters for example so let's change that back in my customers controller we

are required but we also need it to be at least three characters and the way you do that is by adding a pipe and then we could say min : three so this is telling laravel the

name field is required and it needs to be at least three characters all right let's hit save head back over here and then we could say that customer and it says the name must be at least three

characters add customer and there we go now it does add that in so this is the last thing I wanted to show you I'll add the link to this in the description below but just know that if you go to

the documentation of laravel there is these available validation rules and these are all of the rules that you can use and you can pipe together of course we've already used a required and we use

this min rule to not allow anything under three characters to pass through validation so all of these rules combined will help you validate your forms so take a look at each of these as

you have some time and I bet you'll find exactly what you need however do know that you can add custom validation rules and we can cover that in a separate video so as a little bit of an

assignment what I want you to do is I want you to add a second field to our form here for email and I want you to go ahead and change the migration to add that in

because I want to be able to store the name and the email of our customers so give that a shot on your own and then in the next episode I'll show you how to do it

Now that we are adding customers, we need to add some validation to our form. Laravel makes this process very easy, follow along as we make the name field required.

For the best experience, follow along in our interactive school at

Course Source Code
Available Validation Rules

Hit us up on Twitter with any questions or comments @codertape (

About This Course

Ready to get started on your path to Laravel Artisan? In this series, we are breaking down all of the basics of Laravel to get you comfortable using the world’s most popular PHP framework. Let’s get started!

    add to database laravel admin laravel artisan Artisan Command artisan commend create artisan console artisan laravel command authentication in laravel belongsto belongsto laravel example coding tutorials create artisan command create command artisan create new command artisan Create your own crud laravel crud laravel tutorial crud resource laravel crud with file upload custom artisan commands custom artisan commands laravel custom laravel database configuration laravel database relationship digital ocean dotenv eager loading eager loading in laravel eager loading vs lazy loading laravel eloquent eloquent accessors eloquent mutators eloquent orm feature testing laravel fetching data in laravel filesystem laravel form requests full stack vue gate and policy laravel google optimize hasmany hasmany laravel hasmany laravel example hasmany relationship in laravel hasone hasone relationship in laravel How to create how to queue email how to use queue installing laravel intervention image laravel laravel 5 laravel 5 auth laravel 5.4 queue laravel 5.5 queue laravel 5.8 laravel 5.8 artisan command laravel 5.8 artisan console laravel 5.8 auth tutorial laravel 5.8 authentication laravel 5.8 commands laravel 5.8 crud laravel 5.8 crud example laravel 5.8 custom middleware laravel 5.8 deprecations laravel 5.8 eager loading laravel 5.8 elixir laravel 5.8 event listeners laravel 5.8 events laravel 5.8 feature laravel 5.8 features laravel 5.8 global middleware laravel 5.8 install laravel 5.8 lazy loading laravel 5.8 listeners laravel 5.8 middleware laravel 5.8 multi auth laravel 5.8 named resource routes laravel 5.8 named routes laravel 5.8 new feature laravel 5.8 own artisan command laravel 5.8 queue laravel 5.8 queues laravel 5.8 routing laravel 5.8 telescope laravel 5.8 tutorial laravel 5.8 user auth laravel 5.8 user authentication laravel 5.8 what's new laravel 5.9 laravel admin permissions laravel api laravel artisan command laravel artisan console laravel assets laravel auth laravel auth role laravel authentication laravel authorization laravel axios post example laravel background process laravel background task laravel background worker laravel beginner to master laravel belongsto laravel belongsto vs hasone laravel belongstomany laravel best packages laravel best practices laravel best tutorial laravel bootstrap laravel command laravel command line laravel commands tutorial laravel composer install laravel connect db laravel console command laravel console testing laravel contact form send email laravel controllers laravel create laravel crud laravel crud policy laravel custom command laravel custom middleware laravel database laravel database configuration laravel database relationships laravel database seeder laravel database settings laravel db seed laravel db settings laravel debugging laravel deploy aws laravel deploy digital ocean laravel deploy on digitalocean laravel deploy on server laravel deploy to production laravel deployment laravel digitalocean laravel drag and drop file upload laravel dropzone file upload laravel dropzone image upload laravel e-commerce laravel eager loading laravel eager loading tutorial laravel eager loading with condition laravel elixir laravel eloquent laravel eloquent belongsto laravel eloquent crud laravel eloquent hasmany laravel eloquent where laravel eloquest tutorial laravel events and queue laravel events tutorial laravel factory laravel feature test laravel feature testing laravel fetching data from database laravel file storage laravel fillable example laravel flash message notification laravel for beginners laravel form validation laravel forms laravel forms bootstrap snippets laravel from scratch laravel from the ground up laravel front end laravel frontend tutorial laravel gate and policy tutorial laravel global middleware laravel hasmany laravel hasone laravel i18n laravel installation laravel installation mac laravel intervention image tutorial laravel javascript tutorial laravel jobs queue laravel language laravel language switcher laravel language tutorial laravel languages laravel lazy loading laravel listener event laravel listeners laravel localization laravel login laravel mailable tutorial laravel many to many relationship example laravel markdown email laravel markdown mail laravel mass assignment laravel middleware laravel migrate fresh laravel mix laravel mix 5.8 laravel mix vue laravel model factory tutorial laravel multiple language laravel mysql json laravel named resource routes laravel named routes laravel new features laravel news laravel nginx laravel node modules laravel npm install laravel npm run watch error laravel one to one laravel paginate laravel paginate link laravel pagination laravel pagination 5.8 laravel pagination links laravel pagination tutorial laravel phpunit laravel phpunit testing laravel pivot table example laravel policy laravel preview laravel query optimization laravel queue laravel queue event listener laravel react laravel register user laravel registration laravel registration validation laravel relationships laravel reset password laravel role middleware laravel role permission laravel roles laravel route group middleware laravel routes laravel routing laravel routing with parameters laravel sass laravel save file to database laravel scopes laravel seo tutorial laravel server laravel session data laravel ssl laravel supervisor laravel tailwind css laravel tailwind setup laravel tdd laravel tdd tutorial laravel telescope laravel telescope installation laravel telescope tutorial laravel test driven development laravel test workflow laravel testing laravel testing controllers laravel testing tutorial laravel tools laravel translation laravel tutorial laravel tutorial for beginners laravel ubuntu server laravel ubuntu tutorial laravel unit testing controllers laravel upload file laravel upload image to storage laravel upload multiple files at once laravel upload multiple image to database laravel upload multiple images laravel url slug laravel vue laravel vue js crud laravel vue setup laravel vue tutorial laravel vue.js laravel webpack error laravel webpack tutorial lazy loading lazy loading laravel lazy loading vs eager loading learn laravel learn laravel framework step by step localization in laravel localization laravel many to many laravel mvc tutorial for beginners in php mvc tutorial laravel mysql mysql relational database mysql relationship n + 1 problem n + 1 problem laravel new artisan command npm install npm run dev npm run watch laravel one to many one to one one to one laravel own artisan command pagination pagination bootstrap pagination bootstrap php mysql pagination laravel pagination laravel bootstrap pagination links pagination php php php artisan php carbon immutable php framework php framework 2019 php what's new 2019 phpunit phpunit laravel phpunit testing pivot laravel policy laravel polymorphic relationships queue and events queue email queue for laravel queue jobs queue laravel 5.8 registration form relationship laravel eloquent relationship mysql restful controller role permission in laravel roles laravel route model binding laravel routing in laravel save image to database seo friendly seo friendly content writing seo friendly website seo laravel seo optimization simple pagination laravel slugify sqlite relational database sqlite relationships between tables symfony command console symfony laravel tailwind css tailwind laravel mix telescope laravel tutorial laravel unit testing unit testing laravel upload file laravel upload file php upload image laravel upload image to database php upload images laravel upload multiple files in php url slug laravel url slug php vue vue.js vuejs laravel why use laravel queue why use queue